Skip to content

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Oct 19, 2022

I wasn't sure what to name the new predicate on CodeExecution. So I wrote the QLDoc and let Copilot pick a name.

It's my first use of DataFlow::FlowState, but I think I figured it out.

Evaluation looks good.
Neutral performance, and removal of a few results that I think look like FPs.

@github-actions github-actions bot added the Ruby label Oct 19, 2022
@erik-krogh erik-krogh added the no-change-note-required This PR does not need a change note label Oct 19, 2022
@erik-krogh erik-krogh marked this pull request as ready for review October 19, 2022 13:13
@erik-krogh erik-krogh requested a review from a team as a code owner October 19, 2022 13:13
@hmac
Copy link
Contributor

hmac commented Oct 20, 2022

I haven't given this a very thorough review, sorry. I agree that the DCA results all look like FPs. I have a bikeshed suggestion for the predicate name. I can't really comment on the flow state stuff because I've also not used it.

@calumgrant calumgrant requested a review from asgerf October 24, 2022 08:32
Comment on lines -24 to +31
sourceNode = source.getNode()
sourceNode = source.getNode() and
// removing duplications of the same path, but different flow-labels.
sink =
min(DataFlow::PathNode otherSink |
config.hasFlowPath(any(DataFlow::PathNode s | s.getNode() = source.getNode()), otherSink)
|
otherSink order by otherSink.getState()
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like this should be fixed in the shared libraries, the same way we did in JS. I've opened an internal issue for it.

@erik-krogh erik-krogh merged commit ef5132b into github:main Oct 24, 2022
/** Gets a flow state for which this is a sink. */
override DataFlow::FlowState getAFlowState() {
if c.runsArbitraryCode()
then result = [FlowState::substring(), FlowState::full()] // If it runs immediately, then it's always vulnerable.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
then result = [FlowState::substring(), FlowState::full()] // If it runs immediately, then it's always vulnerable.
then result = [FlowState::substring(), FlowState::full()] // If it runs arbitrary code then it's always vulnerable.

*/
class StringConcatenationSanitizer extends Sanitizer {
StringConcatenationSanitizer() {
// string concatenations sanitize the `full` state, as an attacker no longer controls the entire string
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems overly restrictive. User input flowing into eval is still bad even if it is concatenated with some constant string.

params[:foo] = "f; end; system('bad stuff'); def g"

eval("def " + params[:foo] + "; end")
# => def f; end; system('bad stuff'); def g; end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It only restricts flow for the full state, which means that flow are only blocked for the sinks where runsArbitraryCode() does not hold.
That specifically means that your example is still flagged, because flow is not blocked for flow that is heading towards the eval() sink.

But I found an unrelated issue while adding a test that confirmed that it works: #10968

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I tested this myself to check that it didn't work correctly, and I guess was also affected by that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Ruby
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants