Skip to content

Python: Use new dataflow API #14068

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

Merged
merged 55 commits into from
Sep 4, 2023
Merged

Conversation

RasmusWL
Copy link
Member

@RasmusWL RasmusWL commented Aug 28, 2023

Highly recommend reviewing commit by commit 😅

The .expected file will have changes if:

  • The configuration uses isAdditionalFlowStep, since such steps will now always be part of the path-graph (lines added to .expected file)
  • There were previously multiple configurations in scope, which could cause some unrelated PathNodes/edges from other configurations to have been part of the .expected file before. (lines removed from .expected file)

(no change-note like in Go: #13820)

This PR covers all usage I could find in src/ and lib/. I did not focus on test/ yet. We should fix those too, but I don't think it's strictly required right now 😊

@RasmusWL RasmusWL added the no-change-note-required This PR does not need a change note label Aug 28, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 28, 2023

QHelp previews:

python/ql/src/experimental/Security/CWE-522/LdapInsecureAuth.qhelp

Python Insecure LDAP Authentication

Failing to ensure the utilization of SSL in an LDAP connection can cause the entire communication to be sent in cleartext making it easier for an attacker to intercept it.

Recommendation

Always set use_SSL to True, call start_tls_s() or set a proper option flag (ldap.OPT_X_TLS_XXXXXX).

Example

This example shows both good and bad ways to deal with this issue under Python 3.

The first one sets use_SSL to true as a keyword argument whereas the second one fails to provide a value for it, so the default one is used (False).

from ldap3 import Server, Connection, ALL
from flask import request, Flask

app = Flask(__name__)


@app.route("/good")
def good():
    srv = Server(host, port, use_ssl=True)
    conn = Connection(srv, dn, password)
    conn.search(dn, search_filter)
    return conn.response


@app.route("/bad")
def bad():
    srv = Server(host, port)
    conn = Connection(srv, dn, password)
    conn.search(dn, search_filter)
    return conn.response

@RasmusWL RasmusWL force-pushed the dataflow-config-refactor branch 2 times, most recently from 66be4f4 to 18d16b4 Compare August 28, 2023 11:02
We could have switched to a stateful config, but I tried to keep changes
as straight forward as possible.
I adopted helper predicates to do the "heavy" lifting of .asPathNode1(), maybe I like this approach better... let me know what you think 😊
@RasmusWL RasmusWL force-pushed the dataflow-config-refactor branch from 18d16b4 to dadefa0 Compare August 28, 2023 13:44
@RasmusWL RasmusWL force-pushed the dataflow-config-refactor branch from dadefa0 to ce63358 Compare August 28, 2023 14:20
@RasmusWL RasmusWL marked this pull request as ready for review August 28, 2023 15:11
@RasmusWL RasmusWL requested a review from a team as a code owner August 28, 2023 15:11
}

/** Global taint-tracking for detecting "random values that are not cryptographically secure" vulnerabilities. */
module Flow = TaintTracking::Global<Config>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a good reason why this uses the alternative naming convention (option 1)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to keep changes to a minimal. Since it was already inside a properly named module, I let things stay that way.

So no better reason than I tried to get things done 😅

@calumgrant calumgrant requested a review from yoff August 29, 2023 11:25
Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

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

LGTM, just minor comments.
Also, the QL4QL-alerts are interesting, we should probably follow up on those.


predicate isSink(DataFlow::Node sink) { sink instanceof Sink }

predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
Copy link
Contributor

Choose a reason for hiding this comment

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

What was previously covered by super.isSanitizer(node)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nothing 😂 I found that in a few cases I had copied this pattern from JS

Comment on lines +135 to 147
/** Holds if data can flow from `source` to `sink` with `NormalHashFunction::Flow`. */
predicate normalHashFunctionFlowPath(
WeakSensitiveDataHashingFlow::PathNode source, WeakSensitiveDataHashingFlow::PathNode sink
) {
NormalHashFunction::Flow::flowPath(source.asPathNode1(), sink.asPathNode1())
}

/** Holds if data can flow from `source` to `sink` with `ComputationallyExpensiveHashFunction::Flow`. */
predicate computationallyExpensiveHashFunctionFlowPath(
WeakSensitiveDataHashingFlow::PathNode source, WeakSensitiveDataHashingFlow::PathNode sink
) {
ComputationallyExpensiveHashFunction::Flow::flowPath(source.asPathNode2(), sink.asPathNode2())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

exists(UserInputInComparisonConfig config |
config.hasFlowTo(DataFlow2::exprNode(anotherParameter))
)
UserInputInComparisonFlow::flowTo(DataFlow2::exprNode(anotherParameter))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not need DataFlow2 any more?

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 you solved this in a later commit 👍

@RasmusWL
Copy link
Member Author

RasmusWL commented Sep 4, 2023

Also, the QL4QL-alerts are interesting, we should probably follow up on those.

If you're talking about the annotations on https://github.com/github/codeql/pull/14068/checks?check_run_id=16274578369, I don't think I want to do anything about those right now 😊

@RasmusWL RasmusWL merged commit 49f5d38 into github:main Sep 4, 2023
@RasmusWL RasmusWL deleted the dataflow-config-refactor branch September 4, 2023 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation no-change-note-required This PR does not need a change note Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants