Skip to content

Commit 7a36503

Browse files
committed
Errors when URL includes basic auth
1 parent 66f7eac commit 7a36503

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/app/api/remotes/[encodedRemoteConfig]/route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export async function GET(_req: NextRequest, { params }: { params: RemoteSpecifi
5555
return makeAPIErrorResponse(408, "The operation timed out.")
5656
} else if (error.name === ErrorName.NOT_JSON_OR_YAML) {
5757
return makeAPIErrorResponse(400, "Url does not point to a JSON or YAML file.")
58+
} else if (error.name === ErrorName.URL_MAY_NOT_INCLUDE_BASIC_AITH) {
59+
return makeAPIErrorResponse(400, "Url may not include basic auth.")
5860
} else {
5961
return makeAPIErrorResponse(500, error.message)
6062
}

src/common/utils/fileUtils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const ErrorName = {
44
MAX_FILE_SIZE_EXCEEDED: "MaxFileSizeExceededError",
55
TIMEOUT: "TimeoutError",
66
NOT_JSON_OR_YAML: "NotJsonOrYamlError",
7+
URL_MAY_NOT_INCLUDE_BASIC_AITH: "UrlMayNotIncludeBasicAuth"
78
}
89

910
export async function downloadFile(params: {
@@ -21,14 +22,13 @@ export async function downloadFile(params: {
2122
headers["Authorization"] = "Basic " + btoa(`${basicAuthUsername}:${basicAuthPassword}`);
2223
}
2324
// Make sure basic auth is removed from URL.
24-
const urlWithoutAuth = url;
25-
urlWithoutAuth.username = "";
26-
urlWithoutAuth.password = "";
27-
const response = await fetch(urlWithoutAuth, {
28-
method: "GET",
29-
headers,
30-
signal: AbortSignal.any([abortController.signal, timeoutSignal])
31-
});
25+
if ((url.username && url.username.length > 0) || (url.password && url.password.length > 0)) {
26+
const error = new Error("URL may not include basic auth");
27+
error.name = ErrorName.URL_MAY_NOT_INCLUDE_BASIC_AITH;
28+
throw error;
29+
}
30+
let fetchSignal = AbortSignal.any([abortController.signal, timeoutSignal])
31+
const response = await fetch(url, { method: "GET", headers, signal: fetchSignal })
3232
if (!response.body) {
3333
throw new Error("Response body unavailable");
3434
}

0 commit comments

Comments
 (0)