Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Javascript] CWE-348: Client supplied ip used in security check #6864

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

yabeow
Copy link

@yabeow yabeow commented Oct 13, 2021

Hi there,

This merge request ports these two similar queries to Javascript:

I also used local data flow to detect more sanitized cases in Javascript.

@yabeow yabeow requested a review from a team as a code owner October 13, 2021 07:17
@asgerf asgerf requested a review from esbena October 25, 2021 12:40
@esbena
Copy link
Contributor

esbena commented Oct 25, 2021

Thanks. This generally LGTM. I have a few suggestions for code quality improvements.
I think the source and sinks are a bit on the heuristic side, but I am happy to see them merged if they work well in practice.

(I trust that all of the learnings from the two other PRs have made it into this PR.)

node.asExpr().(MethodCallExpr).getMethodName() = "split" and
source = node and
not aa.getIndex().getIntValue() = 0 and
source.flowsTo(aa.getAChildExpr().flow())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAChildExpr should generally not be used, but rather something like getIndex as seen above. What is being expressed in this final conjunct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used getAChildExpr to get the variable being indexed. I think this is the correct way to do this, do you have any other suggestions?

This is the AST tree of temp[temp.length - 1];

Screen Shot 2021-10-29 at 14 27 00

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now, thanks for clarifying. We should just stick to the DataFlow library then. Something like the following should do the trick:

    exists(DataFlow::MethodCallNode split, DataFlow::PropRead read |
       split = node and
      split.getMethodName() = "split" and // n.split(...)
       read = split.getAPropertyRead() // <n.split(...)>[...]
      not read.getPropertyNameExpr().getIntValue() = 0 and

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @esbena,

Sorry for the late reply, I have modified the isSanitizer part and it should look good now. Thanks for your awesome suggestions. Do you have a moment to take a look at it again?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Friendly ping! @esbena

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esbena Hey there!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the delay. I'll take a look now.

@yabeow yabeow force-pushed the js/ClientSuppliedIpUsedInSecurityCheck branch from 9576171 to a818580 Compare November 15, 2021 07:13
Copy link
Contributor

@esbena esbena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, there's one http/HTTP casing mistake left to fix. I have started a final performance check of the query, I'll approve once it looks good.

…IpUsedInSecurityCheck.qhelp

Co-authored-by: Esben Sparre Andreasen <[email protected]>
@esbena
Copy link
Contributor

esbena commented Feb 11, 2022

Have you run this query with vscode and viewed the results?
Queries with @kind path-problem must import PathGraph to output path explanations...

Example:

import DataFlow::PathGraph

@esbena
Copy link
Contributor

esbena commented May 9, 2022

Draft-stating the PR due to inactivity, but feel free to undraft when you have implemented the requested changes.

@esbena esbena marked this pull request as draft May 9, 2022 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants