mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-19 15:33:12 +09:00
Redact credentials from logged request urls (#1074)
The controller logs the url and query of every HTTP request. Plugins doing OAuth get the authorization code as a query parameter on their callback route, so it ended up in the log. redactUrl now accepts a path, code joins the redacted parameter names, and redactQuery covers the parsed query in the log metadata. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2c506df38a
commit
24586a4b7c
3 files changed
+58
-12
No files matched your search
+19
-1
@@ -241,7 +241,7 @@ describe("lib/helpers", function() {
|
||||
lib.redactUrl("https://mods.factorio.com/download/mod?username=user&token=secret"),
|
||||
"https://mods.factorio.com/download/mod?username=user&token=REDACTED"
|
||||
);
|
||||
for (const name of ["access_token", "api_key", "apikey", "password", "secret", "token"]) {
|
||||
for (const name of ["access_token", "api_key", "apikey", "code", "password", "secret", "token"]) {
|
||||
assert.equal(
|
||||
lib.redactUrl(`https://example.com/?${name}=secret`),
|
||||
`https://example.com/?${name}=REDACTED`
|
||||
@@ -272,6 +272,24 @@ describe("lib/helpers", function() {
|
||||
assert.equal(lib.redactUrl("not a url?token=secret"), "not a url?token=secret");
|
||||
assert.equal(lib.redactUrl(""), "");
|
||||
});
|
||||
it("should redact a path with a query string and return a path", function() {
|
||||
assert.equal(
|
||||
lib.redactUrl("/api/plugin/callback?code=secret&state=abc"),
|
||||
"/api/plugin/callback?code=REDACTED&state=abc"
|
||||
);
|
||||
assert.equal(lib.redactUrl("/api/plugin?page=2"), "/api/plugin?page=2");
|
||||
});
|
||||
it("should keep the original encoding when there is nothing to redact", function() {
|
||||
assert.equal(lib.redactUrl("/search?q=a%20b"), "/search?q=a%20b");
|
||||
});
|
||||
});
|
||||
|
||||
describe("redactQuery()", function() {
|
||||
it("should redact credential parameters and keep the rest", function() {
|
||||
const query = { code: "secret", Token: "secret", state: "abc" };
|
||||
assert.deepEqual(lib.redactQuery(query), { code: "REDACTED", Token: "REDACTED", state: "abc" });
|
||||
assert.equal(query.code, "secret");
|
||||
});
|
||||
});
|
||||
|
||||
function parse(input, attributes) {
|
||||
|
||||
Reference in new issue
Block a user