Skip to content

Improve rust tainting#485

Merged
dimitris-m merged 4 commits intomainfrom
dm/fix-rust-letcond-ast-to-il
Dec 10, 2025
Merged

Improve rust tainting#485
dimitris-m merged 4 commits intomainfrom
dm/fix-rust-letcond-ast-to-il

Conversation

@dimitris-m
Copy link
Collaborator

@dimitris-m dimitris-m commented Dec 9, 2025

We now correctly propagate taint when using if let

if let P = E {...} else {...}

For example this target:

fn f(some_x: Option<String>) {
    // ok
    let z = sink(x) 
    if let Some(x) = some_x {
        // ruleid: taint
        sink(x)
    } else {
        // ok
        sink(x)
        // should not hit since x is not defined here!
    }
}

will test as expected with this rule:

rules:
- id: taint
  mode: taint
  languages: [rust]
  message: "tainted"
  severity: INFO
  pattern-sources:
    - patterns:
        - pattern-inside: |
            fn $F(..., $P: $_, ...){...}
        - focus-metavariable: $P
  pattern-sinks:
    - pattern: sink($R)

Other fixes

  • The tests in tainting_tests/ were not running.
  • The macos-13 image is now deprecated in GHA and CI failed on main, this is now fixed by bumping to macos-14.

@dimitris-m dimitris-m removed the request for review from willem-delbare December 9, 2025 23:48
@dimitris-m dimitris-m added taint lang Add or improve language support labels Dec 9, 2025
Copy link
Contributor

@corneliuhoffman corneliuhoffman left a comment

Choose a reason for hiding this comment

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

Happy with it, maybe just add a let with another pattern to the test and call this G.faske "pattern" or something

| Some (rules, target, xlang) -> (
(* expected *)
(* not tororuleid! not ok:! not todook:
(* not todoruleid! not ok:! not todook:
Copy link
Contributor

Choose a reason for hiding this comment

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

:)))

(* Convert to switch(e) { pat -> if_branch, _ -> else_branch }. *)
let cond_opt = Some (G.Cond e) in
let if_case_and_body =
G.CasesAndBody ([ G.Case (G.fake "some", pat) ], st1)
Copy link
Contributor

Choose a reason for hiding this comment

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

seems to me this is specially for a Some pattern no? what if it is a different pattern?

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact I just realised that these are fine bc of Naming ... I only object to the "some" here :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just call it "case" now, it does not matter what name it has, and there is a function in Generic AST that uses that name.

For tainting to work, we treat Rust's LetCond, for example in
code like `if let Some(x) = e {if_branch} else {else_branch}`,
similarly to a LetPattern.

Specifically, the above `If` becomes a `G.Switch` with a condition on
`e`, then a pattern `Some(x) => if_branch` and `G.PatWilcard =>
else_branch`.
The tainting_rules test were not running.
@dimitris-m dimitris-m force-pushed the dm/fix-rust-letcond-ast-to-il branch from ae7369b to 184a394 Compare December 10, 2025 12:18
@dimitris-m dimitris-m merged commit ce1d343 into main Dec 10, 2025
3 checks passed
@dimitris-m dimitris-m deleted the dm/fix-rust-letcond-ast-to-il branch December 10, 2025 12:28
@dimitris-m dimitris-m mentioned this pull request Dec 15, 2025
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Dec 18, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [opengrep/opengrep](https://github.com/opengrep/opengrep) | minor | `v1.12.1` -> `v1.13.2` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>opengrep/opengrep (opengrep/opengrep)</summary>

### [`v1.13.2`](https://github.com/opengrep/opengrep/releases/tag/v1.13.2): Opengrep 1.13.2

[Compare Source](opengrep/opengrep@v1.13.1...v1.13.2)

#### Improvements

- C#: Add matching on function argument modifiers (ref, in, scoped, etc.) by [@&#8203;maciejpirog](https://github.com/maciejpirog) in [#&#8203;494](opengrep/opengrep#494)
- C#: Support extension blocks by [@&#8203;maciejpirog](https://github.com/maciejpirog) in [#&#8203;496](opengrep/opengrep#496)

#### Release process

- Validate tag input on release by [@&#8203;lae](https://github.com/lae) in [#&#8203;493](opengrep/opengrep#493)

**Full Changelog**: <opengrep/opengrep@v1.13.1...v1.13.2>

### [`v1.13.1`](https://github.com/opengrep/opengrep/releases/tag/v1.13.1): Opengrep 1.13.1

[Compare Source](opengrep/opengrep@v1.12.1...v1.13.1)

#### Improvements

- Improve handling of patterns and `AST_to_IL` translation by [@&#8203;dimitris-m](https://github.com/dimitris-m) in [#&#8203;483](opengrep/opengrep#483)
- Improve rust tainting by [@&#8203;dimitris-m](https://github.com/dimitris-m) in [#&#8203;485](opengrep/opengrep#485)
- Dump generic AST to HTML by [@&#8203;maciejpirog](https://github.com/maciejpirog) in [#&#8203;484](opengrep/opengrep#484)
- Modernise C# by [@&#8203;maciejpirog](https://github.com/maciejpirog) in [#&#8203;487](opengrep/opengrep#487)

#### Bug fixes

- Fix for kotlin double-annotation bug by [@&#8203;maciejpirog](https://github.com/maciejpirog) in [#&#8203;480](opengrep/opengrep#480)
- Fix PCRE2 test making OSX build fail by [@&#8203;dimitris-m](https://github.com/dimitris-m) in [#&#8203;486](opengrep/opengrep#486)
- Fix: in `LetPattern(pat, e)`, `e` should be visited first by [@&#8203;dimitris-m](https://github.com/dimitris-m) in [#&#8203;488](opengrep/opengrep#488)

#### CI fixes

- Force python 3.13 for osx binary workflow by [@&#8203;dimitris-m](https://github.com/dimitris-m) in [#&#8203;490](opengrep/opengrep#490)

##### Notes

- Version 1.13.0 ([#&#8203;489](opengrep/opengrep#489)) intentionally skipped due to CI errors, fixed in [#&#8203;490](opengrep/opengrep#490).

**Full Changelog**: <opengrep/opengrep@v1.12.1...v1.13.1>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41Ny4xIiwidXBkYXRlZEluVmVyIjoiNDIuNTcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang Add or improve language support taint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants