Skip to content

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

Draft
yabeow wants to merge 3 commits into
github:mainfrom
yabeow:js/ClientSuppliedIpUsedInSecurityCheck
Draft

[Javascript] CWE-348: Client supplied ip used in security check#6864
yabeow wants to merge 3 commits into
github:mainfrom
yabeow:js/ClientSuppliedIpUsedInSecurityCheck

Conversation

@yabeow

@yabeow yabeow commented Oct 13, 2021

Copy link
Copy Markdown

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

esbena commented Oct 25, 2021

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@esbena esbena left a comment

Copy link
Copy Markdown
Contributor

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 <esbena@github.com>
@esbena

esbena commented Feb 11, 2022

Copy link
Copy Markdown
Contributor

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

esbena commented May 9, 2022

Copy link
Copy Markdown
Contributor

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