| Apr | MAY | Jun |
| 02 | ||
| 2024 | 2025 | 2026 |
COLLECTED BY
Collection: Save Page Now
To see all available qualifiers, see our documentation.
Sign in /cpp/cleartext-transmission). This fills a gap in our existing queries 'Cleartext storage of sensitive information in file' (cpp/cleartext-storage-file), 'Cleartext storage of sensitive information in buffer' (cpp/cleartext-storage-buffer) and 'Cleartext storage of sensitive information in an SQLite database' (cpp/cleartext-storage-database) - and allows us to catch the SAMATE Juliet tests cases for CWE-319.
alibaba/AliSQL is notable as a likely FP, as the path goes through a function encrypt_and_write_file, which presumably does what it says. The result in openwall/john also hints at encryption being present.
Results on SAMATE Juliet tests: https://jenkins.internal.semmle.com/job/Security/job/SAMATE/job/SAMATE-cpp-detailed/163/ --- we catch all of the CWE-319 tests, but unfortunately produce a large number of FPs on that same CWE.
Results on DCA: https://github.com/github/codeql-dca-main/issues/285 --- 448 results in the SAMATE Juliet test, 1 result in git. The latter looks like a reasonable result, and also shows up in the LGTM run (where it's easier to view).
@precision medium for now, with the hopes of fixing most of the FPs in a follow-up and upgrading it to high.
Sorry, something went wrong.
geoffw0 added 12commits
C++: Add CleartextTransmission query.
2463024
C++: Add basic test.
cd5a534
C++: Test dataflow and other slightly more complex cases.
29ad3bf
C++: Support 'send' as well.
1707d67
C++: Support various functions / variants.
3ba9e80
C++: Fix false positives involving STDIN_FILENO.
e696eaa
C++: Full dataflow version.
f58177f
C++: Upgrade to path problem.
ee7ccd7
C++: Add a test demonstrating taint.
0e8064d
C++: We get many more real world results using taint tracking.
67c6b35
C++: Assign precision and severity; medium for now, since there are F…
a3de94e
…Ps in SAMATE Juliet.
CPP: Fix QLDoc comments.
90bc138
C++: Change note.
5124345
MathiasVP
reviewed
Sorry, something went wrong.
cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql| * | ||
| * note: functions such as `write` may be writing to a network source or a file. We could attempt to determine which, and sort results into `cpp/cleartext-transmission` and perhaps `cpp/cleartext-storage-file`. In practice it usually isn't very important which query reports a result as long as its reported exactly once. | ||
| */ | ||
| class NetworkSend extends NetworkSendRecv { |
RemoteFlowSinkFunction?
Sorry, something went wrong.
Contributor AuthorRemoteFlowSinkFunction/RemoteFlowSourceFunction, not a RemoteFlowSinkFunction/RemoteFlowSourceFunction itself, so I'll still have to wrap those - unless there's a cleaner way to wire it up. But this does avoid duplicating the list of functions, which is a good thing.
Second, RemoteFlowSourceFunction doesn't have an equivalent of getSocketExpr() for ruling out reads from standard input. We could have RemoteFlowSourceFunction expose this information or even do the work to rule out these sources itself?
Third, RemoteFlowSourceFunction also includes getEnv (I'm not sure why, I thought the whole point was to be able to specify sources a bit more precisely). So ideally we'd use something finer that doesn't include that (but Recv is currently private).
Sorry, something went wrong.
ContributorRemoteFlowSourceFunction doesn't have an equivalent of getSocketExpr() for ruling out reads from standard input. We could have RemoteFlowSourceFunction expose this information or even do the work to rule out these sources itself?
This seems like a thing we would want to do in RemoteFlowSourceFunction, yeah.
Third, RemoteFlowSourceFunction also includes getEnv (I'm not sure why, I thought the whole point was to be able to specify sources a bit more precisely). So ideally we'd use something finer that doesn't include that (but Recv is currently private).
I think getEnv is only included in LocalFlowSourceFunction, right? That's at least what I see here.
Sorry, something went wrong.
ContributorRemoteFlowSinkFunction/RemoteFlowSourceFunction, not a RemoteFlowSinkFunction/RemoteFlowSourceFunction itself, so I'll still have to wrap those - unless there's a cleaner way to wire it up. But this does avoid duplicating the list of functions, which is a good thing.
We have RemoteFlowSource wrapping RemoteFlowSourceFunctioninsemmle.code.cpp.models.interfaces.FlowSource, but no equivalent for sinks.
Sorry, something went wrong.
Contributor AuthorRemoteFlowSinkFunction?
Could we replace this whole file with RemoteFlowSourceFunction?
I've updated the code to (more-or-less) do this.
The following are considered a RemoteFlowSourceFunction (# = not already modelled by NetworkRecv): recv, recvfrom, recvmsg, read, pread, readv, preadv, preadv2#, gets#, fgets#, fgetws#, getdelim#, getwdelim#, __getdelim#, fread#. Some of the new functions read from a socket, some from a FILE *, and I'm a bit concerned that we'll get overlaps with cpp/cleartext-storage-file from the latter. They're differently structured queries though so I'm not sure this will really be an issue in practice. Probably best to fix it when we see it.
The following are considered a RemoteFlowSinkFunction (all already modelled by NetworkSend): send, sendto, sendmsg, write, writev, pwritev, pwritev2. So no problems there.
We have RemoteFlowSource wrapping RemoteFlowSourceFunctioninsemmle.code.cpp.models.interfaces.FlowSource, but no equivalent for sinks.
This looks promising, but it's in the security.FlowSources lib which conflicts with dataflow.TaintTracking (and as you point out RemoteFlowSink would need to be added). This PR has enough in it that I won't do this change here, but if you feel strongly I can do it as a follow-up?
Second, RemoteFlowSourceFunction doesn't have an equivalent of getSocketExpr() for ruling out reads from standard input. We could have RemoteFlowSourceFunction expose this information or even do the work to rule out these sources itself?
This seems like a thing we would want to do in RemoteFlowSourceFunction, yeah.
It turns out RemoteFlowSourceFunction can't rule out stdin/stdout by itself, as it's modelling the function not the call and thus has no idea of parameter values. We could potentially do this work in an improved RemoteFlowSource class at some point. But for now I've added a hasSocketInput predicate to the two models so that users can tell which parameter is the socket (if any).
I think getEnv is only included in LocalFlowSourceFunction, right?
Correct, thanks.
RemoteFlowSourceFunction and RemoteFlowSinkFunction models. I believe all points above have been addressed, apart from the possible follow-up PR improving RemoteFlowSource.
Sorry, something went wrong.
ContributorFunction rather than Call is that a Function model also applies directly to IR dataflow, whereas a Call model has to be translated. Of course, a Call model can have more details. The hybrid you've arrived at here LGTM.
Sorry, something went wrong.
Contributor AuthorNetworkSend and NetworkReceive parts at the Function level, then look at calls further down. I'll have a go at a refactor...
Sorry, something went wrong.
Contributor AuthorFunctionInput / FunctionOutput to an ExprorDataFlow::Node. Is there a reason we don't have predicates to do this in FunctionInputsAndOutputs.qll?
Sorry, something went wrong.
ContributorFunctionInputsAndOutputs.qll, no. I'll open an issue for it.
Sorry, something went wrong.
cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql Outdated Show resolved Hide resolved geoffw0 added 2commits
Merge branch 'main' into cwe139
24668b2
C++: Accept subpaths in tests.
e7c82d7
34e52ebtoe7c82d7
Compare
C++: Naive translation to use RemoteFlow*Function.
9f59bc8
C++: Add and use getRemoteSocket predicates.
6901d9d
Contributor
Author
|
As discussed elsewhere, the plan is to merge this after the feature freeze (Monday). |
Sorry, something went wrong.
jbj reviewed| // a zero socket descriptor is standard input, which is not interesting for this query. | ||
| not exists(Zero zero | | ||
| DataFlow::localFlow(DataFlow::exprNode(zero), | ||
| DataFlow::exprNode(transmission.getSocketExpr())) | ||
| ) |
Sorry, something went wrong.
Contributor AuthorZero with that will just do it. There is some configurability in Nullness.qll (that defines Zero), but it might be better to use GVN or dataflow instead.
Sorry, something went wrong.
Contributorsocket or similar functions, right?
Sorry, something went wrong.
Contributor AuthorSorry, something went wrong.
cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql| * | ||
| * note: functions such as `write` may be writing to a network source or a file. We could attempt to determine which, and sort results into `cpp/cleartext-transmission` and perhaps `cpp/cleartext-storage-file`. In practice it usually isn't very important which query reports a result as long as its reported exactly once. | ||
| */ | ||
| class NetworkSend extends NetworkSendRecv { |
Function rather than Call is that a Function model also applies directly to IR dataflow, whereas a Call model has to be translated. Of course, a Call model can have more details. The hybrid you've arrived at here LGTM.
Sorry, something went wrong.
Contributor|
I really like the LGTM results for this query even though there are a few FPs. I'm guessing most projects don't realize they've vendored code that will do unencrypted auth to an HTTP server or a proxy server. Maybe that seemed fine 10 years ago. |
Sorry, something went wrong.
geoffw0 and others added 3commits
" data-pjax="true" class="Link--secondary markdown-title" href="/web/20250502085923/https://github.com/github/codeql/pull/6713/commits/10323ac819f930b3503f0899cf666e1798ceb5ec">Update cpp/ql/src/Security/CWE/CWE-311/CleartextStorage.inc.qhelp
10323ac
Co-authored-by: Jonas Jensen <jbj@github.com>
C++: Correct comment.
89098f5
C++: Autoformat.
679b0f9
Contributor
Author
|
Fixed autoformat. There are a couple of things that came up in discussions to be addressed as follow-up, but I believe this PR itself is ready to merge. |
Sorry, something went wrong.
MathiasVP approved these changesSorry, something went wrong.
a3cf721
into
github:main
jbj
rdmarsh2
MathiasVP
Successfully merging this pull request may close these issues.