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
15 changes: 14 additions & 1 deletion src/lib/blockchain-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,20 @@ function sanitizeProviderPathname(pathname: string): string {
throw new Error('Disallowed provider URL path.');
}

return trimmed;
const parts = trimmed.split('/');
const safeSegments: string[] = [];
for (let i = 1; i < parts.length; i++) {
const segment = parts[i];
if (!segment || segment === '.' || segment === '..') {
throw new Error('Disallowed provider URL path.');
}
if (!/^[a-zA-Z0-9\-._~]+$/.test(segment)) {
throw new Error('Disallowed provider URL path.');
}
safeSegments.push(segment);
}

return '/' + safeSegments.join('/');
}

export async function fetchJson(
Expand Down
Loading