Skip to content

Commit 0dfbde0

Browse files
committed
fix: Improve XSSI prefix handling robustness
- Use regex to ensure prefix is only removed from start of string - Make removal conditional on prefix presence - Prevents accidental removal from response body Addresses: brendan-kellam's question about regex rationale
1 parent a050f02 commit 0dfbde0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/backend/src/gerrit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ const fetchAllProjects = async (url: string, auth?: GerritAuthConfig): Promise<G
166166

167167
const text = await response.text();
168168
// Remove XSSI protection prefix that Gerrit adds to JSON responses
169-
const jsonText = text.replace(/^\)\]\}'\n/, '');
169+
// The regex /^\)\]\}'\n/ matches the literal string ")]}'" at the start of the response
170+
// followed by a newline character, which Gerrit adds to prevent JSON hijacking
171+
const jsonText = text.startsWith(")]}'") ? text.replace(/^\)\]\}'\n/, '') : text;
170172
const data: GerritProjects = JSON.parse(jsonText);
171173

172174
// Add fetched projects to allProjects

0 commit comments

Comments
 (0)