Skip to content

Commit 0591e7e

Browse files
committed
Fixed false positive secret detection
1 parent 818e7d8 commit 0591e7e

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,34 @@ This project follows [Keep a Changelog](https://keepachangelog.com/) and [Semant
77

88
### Added
99

10-
-
10+
-
1111

1212
### Changed
1313

14-
-
14+
-
1515

1616
### Fixed
1717

1818
-
1919

2020
## [2.3.12] - 2025-12-18
21+
2122
### Added
23+
2224
- Added warnings count to scan usage stats.
2325

2426
### Changed
27+
2528
- Updated dependencies to latest versions.
2629
- Moved `healthScore` further down on the console output for better visibility of issues.
2730
- Removed used variables output from scan usage to reduce noise.
2831
- Removed header output from scan usage to reduce noise.
2932
- Shortened config file path in CLI output to show only the filename.
3033

34+
### Fixed
35+
36+
- Fixed false positive secret detection for certain harmless attribute keys in codebase scanner.
37+
3138
## [2.3.11] - 2025-12-13
3239

3340
### Changed

src/core/secretDetectors.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const HARMLESS_URLS = [
4444
/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i, // SVG namespace
4545
];
4646

47+
// Known harmless attribute keys commonly used in UI / analytics
48+
const HARMLESS_ATTRIBUTE_KEYS =
49+
/\b(trackingId|trackingContext|data-testid|data-test|aria-label)\b/i;
50+
4751
/**
4852
* Determines the severity of a secret finding.
4953
* @param kind 'pattern' | 'entropy'
@@ -256,7 +260,10 @@ export function detectSecretsInSource(
256260

257261
// 1) Suspicious key literal assignments
258262
if (SUSPICIOUS_KEYS.test(line)) {
259-
const m = line!.match(/=\s*["'`](.+?)["'`]/);
263+
// Ignore known harmless UI / analytics attributes
264+
if (HARMLESS_ATTRIBUTE_KEYS.test(line)) continue;
265+
266+
const m = line.match(/=\s*["'`](.+?)["'`]/);
260267
if (
261268
m &&
262269
m[1] &&

src/ui/scan/printStats.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ export function printStats(
2727
console.log(
2828
chalk.magenta.dim(` Unique variables: ${stats.uniqueVariables}`),
2929
);
30-
console.log(
31-
chalk.magenta.dim(` Warnings: ${stats.warningsCount}`),
32-
);
30+
console.log(chalk.magenta.dim(` Warnings: ${stats.warningsCount}`));
3331
console.log(
3432
chalk.magenta.dim(` Scan duration: ${stats.duration.toFixed(2)}s`),
3533
);

test/e2e/cli.secrets.e2e.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,32 @@ describe('secrets detection (default scan mode)', () => {
270270
expect(res.status).toBe(0);
271271
expect(res.stdout).not.toContain('Potential secrets detected in codebase:');
272272
});
273+
it('does not warn on UI tracking attributes containing auth keywords', () => {
274+
const cwd = tmpDir();
275+
276+
fs.writeFileSync(path.join(cwd, '.env'), 'DUMMY=\n');
277+
fs.mkdirSync(path.join(cwd, 'src'), { recursive: true });
278+
279+
fs.writeFileSync(
280+
path.join(cwd, 'src', 'page.svelte'),
281+
`
282+
<script>
283+
const trackingId = "users-reset-password-button";
284+
const trackingContext = "users-reset-password-confirmation-modal";
285+
</script>
286+
287+
<button
288+
trackingId="users-reset-password-button"
289+
trackingContext="users-reset-password-confirmation-modal"
290+
>
291+
Reset password
292+
</button>
293+
`.trimStart(),
294+
);
295+
296+
const res = runCli(cwd, []);
297+
298+
expect(res.status).toBe(0);
299+
expect(res.stdout).not.toContain('Potential secrets detected in codebase:');
300+
});
273301
});

0 commit comments

Comments
 (0)