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}`;
Copy link

Choose a reason for hiding this comment

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

[❗❗ security]
The change from using the URL constructor to string concatenation for requestUrl reintroduces potential security risks such as path traversal or SSRF (Server-Side Request Forgery). Using the URL constructor helps mitigate these risks by ensuring proper URL parsing and construction. Consider reverting to the previous implementation using the URL constructor.


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