Skip to content

Rust: Add cleartext transmission query #19000

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 4 commits into from
Mar 17, 2025

Conversation

paldepind
Copy link
Contributor

@paldepind paldepind commented Mar 12, 2025

Adds a cleartext transmission query. Large parts of this is heavily inspired or copy/pasted from the corresponding Swift query.

For now one kind of sink is modeled: URLs to requests created with the rekwest library.

@github-actions github-actions bot added documentation Rust Pull requests that update Rust code labels Mar 12, 2025
Copy link
Contributor

github-actions bot commented Mar 12, 2025

QHelp previews:

rust/ql/src/queries/security/CWE-311/CleartextTransmission.qhelp

Cleartext transmission of sensitive information

Sensitive information that is transmitted without encryption may be accessible to an attacker.

Recommendation

Ensure that sensitive information is always encrypted before being transmitted over the network. In general, decrypt sensitive information only at the point where it is necessary for it to be used in cleartext. Avoid transmitting sensitive information when it is not necessary to.

Example

The following example shows three cases of transmitting information. In the 'BAD' case, the transmitted data is sensitive (a credit card number) and is included as cleartext in the URL. URLs are often logged or otherwise visible in cleartext, and should not contain sensitive information.

In the 'GOOD' cases, the data is either not sensitive, or is protected with encryption. When encryption is used, ensure that you select a secure modern encryption algorithm, and put suitable key management practices into place.

func getData() {
	// ...

	// GOOD: not sensitive information
	let body = reqwest::get("https://example.com/song/{faveSong}").await?.text().await?;

	// BAD: sensitive information sent in cleartext in the URL
	let body = reqwest::get(format!("https://example.com/card/{creditCardNo}")).await?.text().await?;

	// GOOD: encrypted sensitive information sent in the URL
	let encryptedPassword = encrypt(password, encryptionKey);
	let body = reqwest::get(format!("https://example.com/card/{creditCardNo}")).await?.text().await?;

	// ...
}

References

@paldepind paldepind force-pushed the rust-cleartext-transmission branch from 20e0e1d to a049aeb Compare March 13, 2025 07:43
@paldepind paldepind force-pushed the rust-cleartext-transmission branch from a049aeb to 4de69c7 Compare March 13, 2025 07:45
@paldepind paldepind marked this pull request as ready for review March 13, 2025 07:58
@paldepind paldepind requested a review from geoffw0 March 13, 2025 08:01
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

Query looks good to me. I've made some comments about specifics of the .qhelp that I think need to be tweaked a little, before we get a docs review.

I'd also like to see a greater diversity of sinks for this query, i.e MaD transmission sink models beyond just reqwest - though this can 100% be planned follow-up work rather than part of this initial PR.

// GOOD: not sensitive information
let body = reqwest::get("https://example.com/data").await?.text().await?;

// BAD: sensitive information sent in cleartext
Copy link
Contributor

Choose a reason for hiding this comment

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

Strictly speaking I think HTTPS URL parameters are encrypted as part of the HTTPS protocol - though there's a significant danger they get logged outside of that encrypted tunnel, e.g. in a cache or log, or possibly the connection isn't as secure as it seems (as described in the first reference linked from the .qhelp). So I think it is indeed BAD but we might want to rephrase our claim as to why? Alternatively, make the example http:// to avoid introducing confusion on this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I actually thought the whole URL would be sent unencrypted. TIL.

Whether to change the description or use http://: I'm not actually entirely sure about the scope of CWE-311. Is sending a password in the URL of an HTTPS request within the scope given that is encrypted in transmission? Personally, I would think the query would be more useful if we just changed the description, as it definitely catches a real problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I'm definitely happy that we catch these results, but in the .qhelp it's important we try to be as clear as possible about what the problem is and to recommend good practices. Passwords are a bit funny because for several reasons they usually require even more care than other kinds of sensitive information, which complicates recommending good practices if we use that as as example.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm happy with the changes you've made already, by the way. If you're happy to you can ask for a docs review.

@paldepind paldepind requested review from a team as code owners March 13, 2025 14:23
@github-actions github-actions bot added C# JS Python Swift Actions Analysis of GitHub Actions labels Mar 13, 2025
@paldepind paldepind removed request for a team March 13, 2025 14:27
private import codeql.rust.elements.internal.generated.Raw
import codeql.rust.elements.Crate
import codeql.rust.elements.internal.ElementImpl::Impl as ElementImpl
import codeql.rust.elements.Module

Check warning

Code scanning / CodeQL

Redundant import Warning generated

Redundant import, the module is already imported inside
codeql.rust.elements.Crate
.
@paldepind paldepind force-pushed the rust-cleartext-transmission branch from abf0a01 to 208776b Compare March 13, 2025 15:30
@github-actions github-actions bot removed C# JS Python Swift Actions Analysis of GitHub Actions labels Mar 13, 2025
@paldepind paldepind force-pushed the rust-cleartext-transmission branch from 1460d90 to fb71866 Compare March 13, 2025 16:37
@@ -9,7 +9,6 @@ extensions:
pack: codeql/rust-all
extensible: sinkModel
data:
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "crate::blocking::get", "Argument[0]", "transmission", "manual"]
Copy link
Contributor

Choose a reason for hiding this comment

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

A question I've been meaning to ask - when the model generator creates a model that we previously manually modelled, how do we know it's deducing it without reference to the existing manual model? i.e. how do we know it could still generate it without the manual model?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a question that I've been asking myself and definitely something we should be aware of.

I think that in the specific case where we have a flow model for a function foo, then that wont be used when we derive models for foo, because the model applies when calling foo and the model generator tries to find a path inside the body of foo. So in that case the model for foo should be safe to delete.

But there might still be other siturations where there's many manual models, and where it's not clear from the generated output whether a manual model can be deleted or or. In that case I think the safest think to do is 1/ delete the manual model, 2/ delete the generated models and 3/ re-run the model generator and confirm that step 1 didn't change the generated models.

I also know that the model generation library has functionality where it's aware of manual models. For instance it's possible to write a manual model that "suppress" generation of models (for instance if it creates bogus models for a specific function). So perhaps there are other aspects that I'm not aware of. This is something that I'll have to look more at, and maybe ask Michael about.

@geoffw0
Copy link
Contributor

geoffw0 commented Mar 13, 2025

DCA 👍

@paldepind paldepind added the ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. label Mar 14, 2025
mchammer01
mchammer01 previously approved these changes Mar 14, 2025
Copy link
Contributor

@mchammer01 mchammer01 left a comment

Choose a reason for hiding this comment

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

Approving on behalf of Docs ✨
2 minor comments/suggestions for your consideration.

@paldepind
Copy link
Contributor Author

Thanks. I've applied the suggestions.

Copy link
Contributor

@mchammer01 mchammer01 left a comment

Choose a reason for hiding this comment

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

Thanks, re-approving for Docs

@paldepind paldepind merged commit 7a18da8 into github:main Mar 17, 2025
18 checks passed
@paldepind paldepind deleted the rust-cleartext-transmission branch March 17, 2025 13:59
* A data flow sink for cleartext transmission vulnerabilities. That is,
* a `DataFlow::Node` of something that is transmitted over a network.
*/
abstract class CleartextTransmissionSink extends DataFlow::Node { }
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 this ought to extend QuerySink::Range instead (cc @geoffw0 ).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it should, but that class is new. I'll make the change and check all the other merged queries do this now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here: #19103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation ready-for-doc-review This PR requires and is ready for review from the GitHub docs team. Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants