Replies: 3 comments 2 replies
-
|
@fredkzk not a bug, but definitely a footgun. when the browser receives two separate the fix is to modify fresh's built-in CSP config instead of adding a separate header. use the // routes/_app.tsx
import { useCSP } from "$fresh/runtime.ts";
export default function App(req: Request, ctx: FreshContext) {
useCSP((csp) => {
csp.directives.imgSrc = [
"'self'",
"https://firebasestorage.googleapis.com",
"data:",
];
});
return <ctx.Component />;
}this modifies the existing CSP header rather than creating a second one. the key takeaway: never set a raw ref: fresh CSP docs |
Beta Was this translation helpful? Give feedback.
-
|
Yeah it's two separate CSP headers and the browser intersects them. Fresh 2's default CSP is emitted by the built-in middleware; override rather than extend. In your route/middleware, set the full |
Beta Was this translation helpful? Give feedback.
-
|
I think this is happening because there are two CSP headers being sent. Even though one of them allows Firebase, the other one from Fresh still has: img-src 'self' data:
TypeScript Code
import { App, csp } from "fresh";
const app = new App()
.use(csp({
csp: [
"img-src 'self' https://firebasestorage.googleapis.com data:",
],
})); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When I want to enable images from firebase
"img-src 'self' https://firebasestorage.googleapis.com data:",my directive becomes a duplicate of the default one"img-src 'self' data:"as seen in the headers.And it refuses to be loaded: violates the following Content Security Policy directive: "img-src 'self' data:"
Is that a big beautiful bug?
Beta Was this translation helpful? Give feedback.
All reactions