Skip to content

Commit 5c043bb

Browse files
committed
fix: replace polynomial regex with loop to resolve CodeQL ReDoS alert
The regex /\/+$/ used to strip trailing slashes from baseUrl was flagged as a polynomial regular expression (ReDoS risk) by CodeQL. Replaced with a simple while/endsWith/slice loop.
1 parent 32bb821 commit 5c043bb

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

sdk_v2/js/src/openai/responsesClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ export class ResponsesClient {
133133
if (!baseUrl || typeof baseUrl !== 'string' || baseUrl.trim() === '') {
134134
throw new Error('baseUrl must be a non-empty string.');
135135
}
136-
// Strip trailing slash for consistent URL construction
137-
this.baseUrl = baseUrl.replace(/\/+$/, '');
136+
// Strip trailing slashes for consistent URL construction
137+
let url = baseUrl;
138+
while (url.endsWith('/')) {
139+
url = url.slice(0, -1);
140+
}
141+
this.baseUrl = url;
138142
this.modelId = modelId;
139143
}
140144

0 commit comments

Comments
 (0)