Skip to content

Commit 5158846

Browse files
committed
fix(observability-map): trim trailing underscores without a backtracking regex
1 parent 69ec5ea commit 5158846

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

internal-packages/observability-map/src/sensitivity.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,12 @@ export const SENSITIVE_SEGMENTS = [
123123
* layout (`resources.impersonation_.view-as.ts`) and changes nothing about what the route does.
124124
*/
125125
function normalizeSegment(segment: string): string {
126-
return segment.replace(/_+$/, "");
126+
// Trimmed by hand rather than with /_+$/, which backtracks polynomially on a run of underscores
127+
// and trips CodeQL. Nothing here is attacker-controlled (the input is a filename read off disk),
128+
// so this is about not spending a reviewer's attention on the alert.
129+
let end = segment.length;
130+
while (end > 0 && segment[end - 1] === "_") end--;
131+
return segment.slice(0, end);
127132
}
128133

129134
export type Sensitivity = { sensitive: boolean; reasons: string[] };

0 commit comments

Comments
 (0)