Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/api/challenges/challenges.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
orderBy,
uniqBy,
} from 'lodash';
import { ConflictException, Injectable } from '@nestjs/common';
import { BadRequestException, ConflictException, Injectable } from '@nestjs/common';
import { isUUID } from 'class-validator';
import { ENV_CONFIG } from 'src/config';
import { Logger } from 'src/shared/global';
Expand Down Expand Up @@ -66,9 +66,7 @@ export class ChallengesService {
throw new BadRequestException('Invalid challengeId provided! Uuid expected!');
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
Using string concatenation for URL construction can lead to issues such as double slashes or missing slashes, especially if TC_API_BASE ends with a slash. Consider using a more robust method to ensure the URL is constructed correctly, such as checking for trailing slashes or using a library designed for URL manipulation.


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