-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[C#] CWE-348: Using a client-supplied IP address in a security check #9339
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
[C#] CWE-348: Using a client-supplied IP address in a security check #9339
Conversation
Hi, any updates? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initial review of QL code only.
} | ||
} | ||
|
||
string clientIpParameterName() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private?
] | ||
} | ||
|
||
string getIpAddressRegex() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private?
* | ||
* For example: `[FromHeader(Name = "X-Forwarded-For")]`. | ||
*/ | ||
private class AspNetCoreActionMethodParameterSource extends ClientSuppliedIpUsedInSecurityCheckSource, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a test for this.
p.getAnAttribute().getType().hasQualifiedName("Microsoft.AspNetCore.Mvc.FromHeaderAttribute") and | ||
p.getAnAttribute().getNamedArgument("Name").(StringLiteral).getValue().toLowerCase() = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably this should be the same attribute? So introduce a new Attribute a
variable and change to
a = p.getAnAttribute() and
a.getType().hasQualifiedName("Microsoft.AspNetCore.Mvc.FromHeaderAttribute") and
a.getNamedArgument("Name").(StringLiteral).getValue().toLowerCase() = clientIpParameterName()
exists(RemoteFlowSource rfs, MethodCall mc | | ||
rfs.asExpr() = mc.getQualifier() and | ||
mc.getArgument(0).(StringLiteral).getValue().toLowerCase() = clientIpParameterName() and | ||
this.getExpr() = mc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So shouldn't it be xHeader
that is the source in this case, and not the method call itself?
// `Request.Headers.TryGetValue("X-Forwarded-For", out var xHeader)` | ||
exists(RemoteFlowSource rfs, MethodCall mc | | ||
rfs.asExpr() = mc.getQualifier() and | ||
mc.getArgument(0).(StringLiteral).getValue().toLowerCase() = clientIpParameterName() and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mc.getTarget().getName() = "TryGetValue"
?
mc.getQualifier().(StringLiteral).getValue() instanceof PrivateHostName and | ||
not mc.getQualifier().(StringLiteral).getValue() = "0:0:0:0:0:0:0:1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The StringLiteral
infix casts should not be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same in other places.
} | ||
|
||
/** A data flow sink for sql operation. */ | ||
private class SqlOperationSink extends ClientSuppliedIpUsedInSecurityCheckSink { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that relevant for this query?
mc.getArgument(0).(MethodCall).getTarget() = s.getSplitMethod() and | ||
not mc.getTarget() | ||
.hasQualifiedName("System.Linq.Enumerable", | ||
["FirstOrDefault<System.String>", "First<System.String>"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it should be just
["FirstOrDefault<>", "First<>"]
Hi there,
This merge request ports these two similar queries to C#: