mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix: Unauthenticated Nostr profile API allows remote config tampering (#13719)
* fix(an-07): apply security fix Generated by staged fix workflow. * fix(an-07): apply security fix Generated by staged fix workflow. * fix(an-07): satisfy lint in plugin auth regression test Replace unsafe unknown-to-string coercion in the gateway plugin auth test helper with explicit string/null/JSON handling so pnpm check passes.
This commit is contained in:
@@ -66,6 +66,27 @@ function buildNostrProfileUrl(accountId: string, suffix = ""): string {
|
||||
return `/api/channels/nostr/${encodeURIComponent(accountId)}/profile${suffix}`;
|
||||
}
|
||||
|
||||
function resolveGatewayHttpAuthHeader(host: OpenClawApp): string | null {
|
||||
const deviceToken = host.hello?.auth?.deviceToken?.trim();
|
||||
if (deviceToken) {
|
||||
return `Bearer ${deviceToken}`;
|
||||
}
|
||||
const token = host.settings.token.trim();
|
||||
if (token) {
|
||||
return `Bearer ${token}`;
|
||||
}
|
||||
const password = host.password.trim();
|
||||
if (password) {
|
||||
return `Bearer ${password}`;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function buildGatewayHttpHeaders(host: OpenClawApp): Record<string, string> {
|
||||
const authorization = resolveGatewayHttpAuthHeader(host);
|
||||
return authorization ? { Authorization: authorization } : {};
|
||||
}
|
||||
|
||||
export function handleNostrProfileEdit(
|
||||
host: OpenClawApp,
|
||||
accountId: string,
|
||||
@@ -133,6 +154,7 @@ export async function handleNostrProfileSave(host: OpenClawApp) {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...buildGatewayHttpHeaders(host),
|
||||
},
|
||||
body: JSON.stringify(state.values),
|
||||
});
|
||||
@@ -203,6 +225,7 @@ export async function handleNostrProfileImport(host: OpenClawApp) {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...buildGatewayHttpHeaders(host),
|
||||
},
|
||||
body: JSON.stringify({ autoMerge: true }),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user