Commit 5373728
security: fix rust-secrets — 12.5% of Rust repos were never scanned
Two defects in the `rust-secrets` job, both found while verifying the
201-repo secret-scanner re-pin sweep.
1. SILENT NO-SCAN (the serious one). The job ran
`grep -rn --include="*.rs" -E "$pattern" src/`. A Cargo workspace keeps
its code in `crates/*/src`, so `src/` does not exist at the root — grep
exits 2, the enclosing `if` reads that as "no match", and the job passes.
Measured across the 64 Rust repos in the sweep: 8 (12.5%) have no root
`src/` and were therefore never scanned at all. Verified on a fixture: a
planted `pub const SERVICE_TOKEN: &str = "…"` in `crates/core/src/lib.rs`
exits 0 under the old job. Another gate that could not fail.
Now scans every `*.rs` in the tree, pruning target/ vendor/ .git/.
2. FALSE POSITIVE ON THE CORRECT PATTERN. `let.*api_key.*=.*"` matches any
`let api_key =` line containing a quote — including
`let api_key = env::var("CLOUDGUARD_API_KEY").ok();`, which is precisely
the practice this job exists to enforce. That was the *only* rust-secrets
failure in the whole sweep (cloudguard-server src/main.rs:59). A gate whose
sole way to go green is to stop reading from the environment is inverted.
Exemptions added mirror the four layers already documented on shell-secrets,
and match on the VALUE or an explicit pragma — never on a file path, because
a path exemption blinds the job to a real secret in the same file (the failure
mode .gitleaks.toml was rewritten to avoid in #512):
- env-lookup RHS, anchored to the assignment and stopped at `;` so a literal
secret with an unrelated env::var mention later on the line still trips;
- URL values (an OAuth endpoint is public, not a credential);
- comment lines;
- inline `// scanner-allow: rust-secrets`.
Widened scope is warn-first to 2026-08-21 — the same cutoff and idiom as
check-package-policy.sh and check-docs-presence.sh — so repos that were never
actually being scanned get a window rather than an immediate red. The advisory
branch prints the finding and says NOT YET ENFORCED; it never claims a pass.
A malformed cutoff refuses to run rather than defaulting to warn forever.
Verified, not assumed:
- 6/6 canary cases pass against the script extracted from this YAML (not a
copy): correct-pattern allowed; secret in ./src blocks; secret in crates/
advisory today and blocking after the cutoff; literal-plus-env-mention
still blocks; malformed cutoff refuses.
- Replayed over all 64 Rust repos in the sweep: 0 regressions today,
1 fixed (cloudguard-server).
- 3 repos (echidnabot, filesoup, heterogenous-mobile-computing) carry
fixture-shaped hits outside ./src and need a one-line pragma before
2026-08-21; each is listed in the run output today.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 8813ecf commit 5373728
1 file changed
Lines changed: 99 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
134 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
135 | 156 | | |
136 | 157 | | |
137 | 158 | | |
138 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
139 | 178 | | |
140 | 179 | | |
141 | 180 | | |
| |||
145 | 184 | | |
146 | 185 | | |
147 | 186 | | |
148 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
149 | 212 | | |
150 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
151 | 229 | | |
152 | | - | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
153 | 242 | | |
154 | 243 | | |
155 | 244 | | |
156 | | - | |
| 245 | + | |
157 | 246 | | |
158 | 247 | | |
159 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
160 | 255 | | |
161 | 256 | | |
162 | 257 | | |
| |||
0 commit comments