mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-30 21:01:54 +08:00
fix: build authHeaders via Map in rewrite-template-source route
Per team dynamic-key-object rule (greptile P2): accumulate the forwarded x-stack-*/x-hexclave-* auth headers in a Map<string, string> to avoid prototype-pollution risk, then convert to a plain object at the call boundary into rewriteTemplateSourceWithAI.
This commit is contained in:
parent
e6c335a913
commit
f02f8211c6
@ -31,14 +31,15 @@ export const POST = createSmartRouteHandler({
|
||||
// (which is a fresh HTTP request to /ai/query/generate) is authenticated
|
||||
// and resolves to the authenticated model tier rather than falling back
|
||||
// to the unauthenticated one.
|
||||
const authHeaders: Record<string, string> = {};
|
||||
const authHeadersMap = new Map<string, string>();
|
||||
for (const [key, value] of Object.entries(fullReq.headers)) {
|
||||
if (value == null) continue;
|
||||
const lower = key.toLowerCase();
|
||||
if (lower.startsWith("x-stack-") || lower.startsWith("x-hexclave-")) {
|
||||
authHeaders[key] = value.join(",");
|
||||
authHeadersMap.set(key, value.join(","));
|
||||
}
|
||||
}
|
||||
const authHeaders: Record<string, string> = Object.fromEntries(authHeadersMap);
|
||||
|
||||
const rewriteResult = await rewriteTemplateSourceWithAI(body.template_tsx_source, authHeaders);
|
||||
if (rewriteResult.status === "error") {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user