mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-12-05 05:38:22 +00:00
fix(server): allow data and blob media fetches in CSP (#4434)
Co-authored-by: kimi-agent-bot <kimi-agent-bot@users.noreply.github.com>
This commit is contained in:
parent
98c1cfbfbd
commit
f47400a418
5 changed files with 15 additions and 3 deletions
5
.changeset/fix-web-csp-media-connect.md
Normal file
5
.changeset/fix-web-csp-media-connect.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@moonshot-ai/kimi-code": patch
|
||||
---
|
||||
|
||||
Fix copying and saving data and blob images on non-loopback Web connections.
|
||||
|
|
@ -6,7 +6,7 @@ export interface SecurityHeadersOptions {
|
|||
|
||||
const HSTS_VALUE = 'max-age=31536000';
|
||||
const CONTENT_SECURITY_POLICY =
|
||||
"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; form-action 'self'; base-uri 'none'; frame-ancestors 'self'";
|
||||
"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' data: blob:; font-src 'self' data:; form-action 'self'; base-uri 'none'; frame-ancestors 'self'";
|
||||
|
||||
export function createSecurityHeadersHook(
|
||||
opts: SecurityHeadersOptions,
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ describe('real password path (verifyPassword)', () => {
|
|||
expect(res.status).toBe(200);
|
||||
expect(res.headers.get('x-content-type-options')).toBe('nosniff');
|
||||
expect(res.headers.get('content-security-policy')).toBe(
|
||||
"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; form-action 'self'; base-uri 'none'; frame-ancestors 'self'",
|
||||
"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' data: blob:; font-src 'self' data:; form-action 'self'; base-uri 'none'; frame-ancestors 'self'",
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ describe('server-v2 exposure hardening hooks', () => {
|
|||
expect(res.headers['x-content-type-options']).toBe('nosniff');
|
||||
expect(res.headers['referrer-policy']).toBe('no-referrer');
|
||||
expect(res.headers['content-security-policy']).toBe(
|
||||
"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; form-action 'self'; base-uri 'none'; frame-ancestors 'self'",
|
||||
"default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; connect-src 'self' data: blob:; font-src 'self' data:; form-action 'self'; base-uri 'none'; frame-ancestors 'self'",
|
||||
);
|
||||
expect(res.headers['strict-transport-security']).toBeUndefined();
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,13 @@ describe('createSecurityHeadersHook', () => {
|
|||
expect(effectiveScriptSrc).not.toContain('data:');
|
||||
});
|
||||
|
||||
it('allows data and blob media fetches on the existing API origin', async () => {
|
||||
const { headers, reply } = captureHeaders();
|
||||
await createSecurityHeadersHook({ tls: false })({} as never, reply as never, 'payload');
|
||||
const directives = parseCsp(headers.get('content-security-policy') ?? '');
|
||||
expect(directives.get('connect-src')).toEqual(["'self'", 'data:', 'blob:']);
|
||||
});
|
||||
|
||||
it('emits HSTS only when TLS is terminated at the server', async () => {
|
||||
const plain = captureHeaders();
|
||||
await createSecurityHeadersHook({ tls: false })({} as never, plain.reply as never, '');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue