Skip to content

Commit 0a63fca

Browse files
vaindclaude
andcommitted
security: replace ReDoS-vulnerable regex with safe string parsing
- Replace regex `/\([^)]*\)/` with indexOf/substring approach - Prevents potential ReDoS attacks with nested parentheses - Improves performance and readability - Add comprehensive edge case tests for malformed scope inputs 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a5c9a66 commit 0a63fca

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

danger/dangerfile-utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ function getFlavorConfig(prFlavor) {
4343
const normalizedFlavor = prFlavor.toLowerCase().trim();
4444

4545
// Strip scope/context from conventional commit format: "type(scope)" -> "type"
46-
const baseType = normalizedFlavor.replace(/\([^)]*\)/, '');
46+
const parenIndex = normalizedFlavor.indexOf('(');
47+
const baseType = parenIndex !== -1 ? normalizedFlavor.substring(0, parenIndex) : normalizedFlavor;
4748

4849
const config = FLAVOR_CONFIG.find(config =>
4950
config.labels.includes(normalizedFlavor) || config.labels.includes(baseType)

danger/dangerfile-utils.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ describe('dangerfile-utils', () => {
8989

9090
const scopedChore = getFlavorConfig('chore(deps)');
9191
assert.strictEqual(scopedChore.changelog, undefined);
92+
93+
// Test edge cases for scope stripping
94+
const nestedParens = getFlavorConfig('feat(scope(nested))');
95+
assert.strictEqual(nestedParens.changelog, 'Features'); // Should strip at first (
96+
97+
const noCloseParen = getFlavorConfig('feat(scope');
98+
assert.strictEqual(noCloseParen.changelog, 'Features'); // Should still work
99+
100+
const multipleParens = getFlavorConfig('feat(scope1)(scope2)');
101+
assert.strictEqual(multipleParens.changelog, 'Features'); // Should strip at first (
92102
});
93103
});
94104

0 commit comments

Comments
 (0)