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
11 changes: 9 additions & 2 deletions packages/core/src/server/assets-middleware/getFileFromUrl.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type { Stats as FSStats } from 'node:fs';
import path from 'node:path';
import { unescape as qsUnescape } from 'node:querystring';
import { getPathnameFromUrl } from '../../helpers/path';
import type { InternalContext } from '../../types';
import type { OutputFileSystem } from './index';

const UP_PATH_REGEXP = /(?:^|[\\/])\.\.(?:[\\/]|$)/;

function decodePath(input: string) {
try {
return decodeURIComponent(input);
} catch {
return input;
}
}

/**
* Resolves URL to file path with security checks and retrieves file from
* the build output directories.
Expand All @@ -18,7 +25,7 @@ export async function getFileFromUrl(
): Promise<
{ filename: string; fsStats: FSStats } | { errorCode: number } | undefined
> {
const pathname = qsUnescape(getPathnameFromUrl(url));
const pathname = decodePath(getPathnameFromUrl(url));

if (!pathname) {
return;
Expand Down
Loading