Skip to content
Open
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: 15 additions & 0 deletions plugins/expo/skills/expo-cicd-workflows/scripts/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ function parseMaxAge(cacheControl) {
return match ? parseInt(match[1], 10) : null;
}

const ALLOWED_URL_PREFIXES = [
'https://api.expo.dev/',
'https://raw.githubusercontent.com/expo/',
'https://docs.expo.dev/',
];

function assertAllowedUrl(url) {
if (!ALLOWED_URL_PREFIXES.some((prefix) => url.startsWith(prefix))) {
throw new Error(
`URL not permitted. Allowed prefixes:\n${ALLOWED_URL_PREFIXES.map((p) => ` ${p}`).join('\n')}`
);
}
}

if (import.meta.main) {
const url = process.argv[2];

Expand All @@ -104,6 +118,7 @@ Cache is stored in: ${CACHE_DIRECTORY}/`);
process.exit(url ? 0 : 1);
}

assertAllowedUrl(url);
const data = await fetchCached(url);
console.log(data);
}