mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-09 03:22:40 +00:00
fix(package): scope trusted URL auth to original origin
This commit is contained in:
@@ -963,10 +963,13 @@ function validateTrustedPackageDownloadUrl(parsed, trustedSource, options = {})
|
||||
}
|
||||
}
|
||||
|
||||
function createTrustedPackageAuthHeaders(trustedSource) {
|
||||
function createTrustedPackageAuthHeaders(trustedSource, parsed, initialOrigin) {
|
||||
if (!trustedSource?.auth) {
|
||||
return undefined;
|
||||
}
|
||||
if (parsed.origin !== initialOrigin) {
|
||||
return undefined;
|
||||
}
|
||||
const token = process.env[TRUSTED_PACKAGE_SOURCE_TOKEN_ENV];
|
||||
if (!token) {
|
||||
throw new Error(
|
||||
@@ -1193,8 +1196,8 @@ async function openPackageDownloadResponse(url, options) {
|
||||
const timeoutMs = options.timeoutMs ?? PACKAGE_URL_DOWNLOAD_TIMEOUT_MS;
|
||||
const maxRedirects = options.maxRedirects ?? PACKAGE_URL_MAX_REDIRECTS;
|
||||
const trustedSource = options.trustedSource;
|
||||
const headers = createTrustedPackageAuthHeaders(trustedSource);
|
||||
let parsed = new URL(url);
|
||||
const initialOrigin = parsed.origin;
|
||||
for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount += 1) {
|
||||
if (trustedSource) {
|
||||
validateTrustedPackageDownloadUrl(parsed, trustedSource, { isRedirect: redirectCount > 0 });
|
||||
@@ -1202,6 +1205,7 @@ async function openPackageDownloadResponse(url, options) {
|
||||
validatePackageDownloadUrl(parsed);
|
||||
}
|
||||
const addresses = await resolvePackageDownloadAddresses(parsed, lookupHost, trustedSource);
|
||||
const headers = createTrustedPackageAuthHeaders(trustedSource, parsed, initialOrigin);
|
||||
const opened = options.fetchImpl
|
||||
? await openFetchPackageDownloadResponse(parsed, {
|
||||
fetchImpl: options.fetchImpl,
|
||||
|
||||
Reference in New Issue
Block a user