Skip to content

Rust: Models for log_err #19546

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 6 commits into from
May 22, 2025
Merged

Rust: Models for log_err #19546

merged 6 commits into from
May 22, 2025

Conversation

geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented May 20, 2025

Model logging sinks for log_err. The test is based on the code I generated in the demo last week.

@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 16:55
@geoffw0 geoffw0 requested a review from a team as a code owner May 20, 2025 16:55
@geoffw0 geoffw0 added the Rust Pull requests that update Rust code label May 20, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for modeling the log_err crate’s logging sinks and updates tests accordingly

  • Introduce tests in test_logging.rs for log_expect and log_unwrap on both Option and Result
  • Add log_err as a dependency in the test harness
  • Extend log.model.yml to mark log_err methods as potential cleartext-logging sources

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
rust/ql/test/query-tests/security/CWE-312/test_logging.rs Added imports and tests covering log_expect/log_unwrap sinks
rust/ql/test/query-tests/security/CWE-312/options.yml Added log_err = { version = "1.1.1" } as a dependency
rust/ql/lib/codeql/rust/frameworks/log.model.yml Extended the logging model to include log_err sink signatures
Comments suppressed due to low confidence (2)

rust/ql/lib/codeql/rust/frameworks/log.model.yml:20

  • The model currently covers Option::log_expect but lacks an entry for Option::log_unwrap. If log_unwrap panics on None, it may log cleartext; add a corresponding extension entry for <crate::option::Option as crate::LogErrOption>::log_unwrap to capture that.
-      - ["repo:https://github.com/DesmondWillowbrook/rs-log_err:log_err", "<crate::option::Option as crate::LogErrOption>::log_expect", "Argument[0]", "log-injection", "manual"]

rust/ql/test/query-tests/security/CWE-312/test_logging.rs:163

  • No test case covers Option::log_unwrap on a None value. Add a test for None.log_unwrap() to verify the model flags a cleartext-logging alert when unwrapping fails.
    let _ = sensitive_opt2.log_unwrap();


// test `log_expect` with sensitive `Result.Err`
let err_result2: Result<String, String> = Err(password2.clone());
let _ = err_result2.log_expect(""); // $ MISSING: Alert[rust/cleartext-logging]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason we don't find this result is because the model for clone assumes self would be a reference, but here we do not realize that password2 is (I believe) implicitly converted to a reference, so we lose the flow. We've seen similar issues a few times before.

@geoffw0
Copy link
Contributor Author

geoffw0 commented May 21, 2025

No changes on the DCA run. Just waiting for approval.

@geoffw0 geoffw0 merged commit 09dd000 into github:main May 22, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants