Allow 127.X.X.X loopback hostnames

This commit is contained in:
Stan Wohlwend 2024-05-25 18:37:07 +02:00
parent 9653aca0d2
commit 2a6c4e9f34
2 changed files with 13 additions and 2 deletions

View File

@ -1,7 +1,7 @@
import { DomainConfigJson } from "@stackframe/stack-shared/dist/interface/clientInterface";
export function validateUrl(url: string, domains: DomainConfigJson[], allowLocalhost: boolean): boolean {
if (allowLocalhost && (new URL(url).hostname === "localhost" || new URL(url).hostname === "127.0.0.1")) {
if (allowLocalhost && (new URL(url).hostname === "localhost" || new URL(url).hostname.match(/^127\.\d+\.\d+\.\d+$/))) {
return true;
}
return domains.some((domain) => {

View File

@ -382,7 +382,18 @@ export class StackClientInterface {
},
};
const rawRes = await fetch(url, params);
let rawRes;
try {
rawRes = await fetch(url, params);
} catch (e) {
if (e instanceof TypeError) {
// Network error, retry
console.log("Stack detected a network error, retrying.", e);
return Result.error(e);
}
throw e;
}
const processedRes = await this._processResponse(rawRes);
if (processedRes.status === "error") {
// If the access token is expired, reset it and retry