mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-27 00:29:34 +00:00
fix(qa): preserve adjacent control ui redaction
This commit is contained in:
@@ -425,6 +425,19 @@ describe("qa-lab server", () => {
|
||||
};
|
||||
expect(startupStatus.status.gateway.url).toBe("https://gateway.example.test/?panel=chat");
|
||||
|
||||
lab.setControlUi({
|
||||
controlUiUrl:
|
||||
"/control-ui/?token=late-token&api_key=late-api-key&id_token=late-id-token&panel=chat#token=fragment-token",
|
||||
});
|
||||
const relativeBootstrap = (await (
|
||||
await fetchWithRetry(`${lab.baseUrl}/api/bootstrap`)
|
||||
).json()) as {
|
||||
controlUiUrl: string | null;
|
||||
controlUiEmbeddedUrl: string | null;
|
||||
};
|
||||
expect(relativeBootstrap.controlUiUrl).toBe("/control-ui/?panel=chat");
|
||||
expect(relativeBootstrap.controlUiEmbeddedUrl).toBe("/control-ui/?panel=chat");
|
||||
|
||||
const messageResponse = await fetch(`${lab.baseUrl}/api/inbound/message`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
@@ -148,6 +148,24 @@ const CONTROL_UI_CREDENTIAL_QUERY_KEYS = new Set([
|
||||
"refresh_token",
|
||||
"token",
|
||||
]);
|
||||
const CONTROL_UI_CREDENTIAL_QUERY_PATTERN =
|
||||
/([?&])(?:access_token|api_?key|auth|deviceToken|id_token|password|refresh_token|token)=[^&#\s]*&?/gi;
|
||||
|
||||
function stripSensitiveQueryParamsFromText(rawUrl: string): string {
|
||||
let sanitized = rawUrl;
|
||||
for (;;) {
|
||||
const next = sanitized
|
||||
.replace(CONTROL_UI_CREDENTIAL_QUERY_PATTERN, (match: string, separator: string) =>
|
||||
match.endsWith("&") ? separator : "",
|
||||
)
|
||||
.replace(/[?&]$/, "")
|
||||
.replace("?&", "?");
|
||||
if (next === sanitized) {
|
||||
return next;
|
||||
}
|
||||
sanitized = next;
|
||||
}
|
||||
}
|
||||
|
||||
function stripSensitiveQueryParams(rawUrl: string): string {
|
||||
try {
|
||||
@@ -159,13 +177,7 @@ function stripSensitiveQueryParams(rawUrl: string): string {
|
||||
}
|
||||
return url.toString();
|
||||
} catch {
|
||||
return rawUrl
|
||||
.replace(
|
||||
/([?&])(?:access_token|api_?key|auth|deviceToken|id_token|password|refresh_token|token)=[^&#\s]*&?/gi,
|
||||
(match: string, separator: string) => (match.endsWith("&") ? separator : ""),
|
||||
)
|
||||
.replace(/[?&]$/, "")
|
||||
.replace("?&", "?");
|
||||
return stripSensitiveQueryParamsFromText(rawUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user