-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add missing string replacement sanitizers to log-injection and string-break #11910
Add missing string replacement sanitizers to log-injection and string-break #11910
Conversation
6282385
to
9d2d4f4
Compare
Performance evaluation showed no changes |
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.
Looks good to me aside from the one question I added, but might also be good for @smowton to sanity check in case I have missed something.
class StringsNewReplacerCall extends DataFlow::CallNode { | ||
StringsNewReplacerCall() { this.getTarget().hasQualifiedName("strings", "NewReplacer") } | ||
|
||
/** | ||
* Gets an argument to this call corresponding to a string that will be | ||
* replaced. | ||
*/ | ||
DataFlow::Node getAReplacedArgument() { | ||
exists(int n | n % 2 = 0 and result = this.getArgument(n)) | ||
} | ||
} | ||
|
||
/** | ||
* A configuration for tracking flow from a call to `strings.NewReplacer` to | ||
* the receiver of a call to `strings.Replacer.Replace` or | ||
* `strings.Replacer.WriteString`. | ||
*/ | ||
class StringsNewReplacerConfiguration extends DataFlow2::Configuration { | ||
StringsNewReplacerConfiguration() { this = "StringsNewReplacerConfiguration" } | ||
|
||
override predicate isSource(DataFlow::Node source) { source instanceof StringsNewReplacerCall } | ||
|
||
override predicate isSink(DataFlow::Node sink) { | ||
exists(DataFlow::MethodCallNode call | | ||
sink = call.getReceiver() and | ||
call.getTarget().hasQualifiedName("strings", "Replacer", ["Replace", "WriteString"]) | ||
) | ||
} | ||
} |
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.
This part seems to be identical between LogInjectionCustomizations
and StringBreakCustomizations
. Would it make sense / be possible to de-duplicate this in a shared location?
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.
Good idea. It feels like something that should be usable in many different places. I've moved it to StringOps.qll
, which should hopefully make that simple. I've started a performance evaluation as this is a fairly major change.
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 performance analysis was neutral.
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.
Looks good -- no comments on top of @mbg's query
9d2d4f4
to
3fda9f6
Compare
I've updated this to use its own copy of the dataflow library. The failing QLDoc test is because of an undocumented predicate in the dataflow library, which obviously I'm not going to fix in this PR, so I believe it should be ignored. |
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.
Made an import of an internal library private; otherwise LGTM
Add
strings.Replacer.Replace
andstrings.Replacer.WriteString
as sanitizers for log-injection and string-break.This is a resurrection of github/codeql-go#731.