fix: __FRSH_STATE potentially being overwritten by user code (#2256)
As outlined in https://github.com/denoland/fresh/issues/2254 it was possible to overwrite the script tag that is used by Fresh to pass island props from the server to the client. This could be done by injecting raw HTML via `dangerouslySetInnerHTML` and simply using the same id that Fresh was using. With this PR we generate a unique id per render that cannot be guessed anymore. It's composed of `__FRSH_STATE_<uuid>`
This commit is contained in:
@@ -669,7 +669,7 @@ const createRenderNotFound = (
|
||||
return async (req, ctx) => {
|
||||
const notFound = extractResult.notFound;
|
||||
if (!notFound.component) {
|
||||
return sendResponse(["Not found.", undefined], {
|
||||
return sendResponse(["Not found.", "", undefined], {
|
||||
status: STATUS_CODE.NotFound,
|
||||
isDev: dev,
|
||||
statusText: undefined,
|
||||
@@ -771,7 +771,7 @@ function collectEntrypoints(
|
||||
}
|
||||
|
||||
function sendResponse(
|
||||
resp: [string, ContentSecurityPolicy | undefined],
|
||||
resp: [string, string, ContentSecurityPolicy | undefined],
|
||||
options: {
|
||||
status: number;
|
||||
statusText: string | undefined;
|
||||
@@ -779,11 +779,12 @@ function sendResponse(
|
||||
isDev: boolean;
|
||||
},
|
||||
) {
|
||||
const [body, uuid, csp] = resp;
|
||||
const headers: Record<string, string> = {
|
||||
"content-type": "text/html; charset=utf-8",
|
||||
"x-fresh-uuid": uuid,
|
||||
};
|
||||
|
||||
const [body, csp] = resp;
|
||||
if (csp) {
|
||||
if (options.isDev) {
|
||||
csp.directives.connectSrc = [
|
||||
|
||||
Reference in New Issue
Block a user