Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions services/appraisal-api/src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,23 @@ describe("configFromEnv failure modes", () => {
);
});
});

describe("RPC URL embedded credentials", () => {
for (const credentials of ["private-user@", ":private-password@", "private-user:private-password@", "private%2Duser:private%2Dpassword@"]) {
test(`rejects credential form ${credentials.indexOf(":") >= 0 ? "password" : "username"}`, () => {
assert.throws(() => configFromEnv({ ...MINIMAL_ENV, RPC_URL: `https://${credentials}rpc.example/` }), (error: unknown) => {
assert.ok(error instanceof AppraisalConfigError);
assert.equal(error.variable, "RPC_URL");
assert.match(error.message, /embedded credentials/);
assert.doesNotMatch(error.stack ?? error.message, /private-user|private-password|private%2D/);
assert.equal(error.cause, undefined);
return true;
});
});
}
for (const RPC_URL of ["http://localhost:8000", "https://rpc.example/path"]) {
test(`accepts credential-free ${RPC_URL}`, () => {
assert.equal(configFromEnv({ ...MINIMAL_ENV, RPC_URL }).rpcUrl, RPC_URL);
});
}
});
Comment on lines +163 to +181
4 changes: 4 additions & 0 deletions services/appraisal-api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ function parseRpcUrl(
if (url.protocol !== "https:" && url.protocol !== "http:") {
throw new Error("unsupported protocol");
}
if (url.username || url.password) {
throw new AppraisalConfigError("RPC_URL", "must not contain embedded credentials");
}
return url.toString().replace(/\/$/, "");
} catch (cause) {
if (cause instanceof AppraisalConfigError) throw cause;
throw new AppraisalConfigError(
"RPC_URL",
`must be a valid http(s) URL, got ${JSON.stringify(value)}`,
Expand Down
Loading