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
14 changes: 8 additions & 6 deletions src/lib/blockchain-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ export async function fetchJson(
revalidate?: number,
): Promise<any> {
const origin = TRUSTED_ORIGINS[host];

const hostPathPolicies = ALLOWED_PATHS[host];
if (!hostPathPolicies || !hostPathPolicies.some((rx) => rx.test(pathname))) {
throw new Error('Disallowed provider URL path.');
}

const url = new URL(pathname, origin);

if (query) {
for (const [key, value] of Object.entries(query)) {
url.searchParams.set(key, value);
}
}

const hostPathPolicies = ALLOWED_PATHS[host];
const canonicalPathname = url.pathname;
const hasDotSegments = canonicalPathname.split('/').some((segment) => segment === '.' || segment === '..');
if (hasDotSegments || !hostPathPolicies || !hostPathPolicies.some((rx) => rx.test(canonicalPathname))) {
throw new Error('Disallowed provider URL path.');
}

if (url.origin !== origin || url.protocol !== 'https:') {
throw new Error('URL construction resulted in an unexpected origin.');
}
Expand Down
Loading