Skip to content

Commit e15cb82

Browse files
committed
fix(appraisal): reject RPC URL credentials (#257)
1 parent 93ae815 commit e15cb82

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

services/appraisal-api/src/config.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,23 @@ describe("configFromEnv failure modes", () => {
159159
);
160160
});
161161
});
162+
163+
describe("RPC URL embedded credentials", () => {
164+
for (const credentials of ["private-user@", ":private-password@", "private-user:private-password@", "private%2Duser:private%2Dpassword@"]) {
165+
test(`rejects credential form ${credentials.indexOf(":") >= 0 ? "password" : "username"}`, () => {
166+
assert.throws(() => configFromEnv({ ...MINIMAL_ENV, RPC_URL: `https://${credentials}rpc.example/` }), (error: unknown) => {
167+
assert.ok(error instanceof AppraisalConfigError);
168+
assert.equal(error.variable, "RPC_URL");
169+
assert.match(error.message, /embedded credentials/);
170+
assert.doesNotMatch(error.stack ?? error.message, /private-user|private-password|private%2D/);
171+
assert.equal(error.cause, undefined);
172+
return true;
173+
});
174+
});
175+
}
176+
for (const RPC_URL of ["http://localhost:8000", "https://rpc.example/path"]) {
177+
test(`accepts credential-free ${RPC_URL}`, () => {
178+
assert.equal(configFromEnv({ ...MINIMAL_ENV, RPC_URL }).rpcUrl, RPC_URL);
179+
});
180+
}
181+
});

services/appraisal-api/src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@ function parseRpcUrl(
121121
if (url.protocol !== "https:" && url.protocol !== "http:") {
122122
throw new Error("unsupported protocol");
123123
}
124+
if (url.username || url.password) {
125+
throw new AppraisalConfigError("RPC_URL", "must not contain embedded credentials");
126+
}
124127
return url.toString().replace(/\/$/, "");
125128
} catch (cause) {
129+
if (cause instanceof AppraisalConfigError) throw cause;
126130
throw new AppraisalConfigError(
127131
"RPC_URL",
128132
`must be a valid http(s) URL, got ${JSON.stringify(value)}`,

0 commit comments

Comments
 (0)