Skip to content

Commit bf68fd9

Browse files
authored
Merge pull request #115 from topcoder-platform/alert-autofix-2
Potential fix for code scanning alert no. 2: Server-side request forgery
2 parents ab95754 + 6f3ce02 commit bf68fd9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/api/challenges/challenges.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export class ChallengesService {
6161
) {}
6262

6363
async getChallenge(challengeId: string) {
64-
const requestUrl = `${TC_API_BASE}/challenges/${challengeId}`;
64+
// Use the URL constructor to avoid path traversal/SSRF risks.
65+
const baseUrl = TC_API_BASE.endsWith('/') ? TC_API_BASE.slice(0, -1) : TC_API_BASE;
66+
const requestUrl = new URL(`/challenges/${challengeId}`, baseUrl).toString();
6567

6668
try {
6769
const challenge = await this.m2MService.m2mFetch<Challenge>(requestUrl);

0 commit comments

Comments
 (0)