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:
@@ -74,6 +74,7 @@ import * as $route_groups_bar_boof_index from "./routes/route-groups/(bar)/boof/
|
||||
import * as $route_groups_foo_layout from "./routes/route-groups/(foo)/_layout.tsx";
|
||||
import * as $route_groups_foo_index from "./routes/route-groups/(foo)/index.tsx";
|
||||
import * as $signal_shared from "./routes/signal_shared.tsx";
|
||||
import * as $spoof_state from "./routes/spoof_state.tsx";
|
||||
import * as $state_in_props_middleware from "./routes/state-in-props/_middleware.ts";
|
||||
import * as $state_in_props_index from "./routes/state-in-props/index.tsx";
|
||||
import * as $state_middleware_middleware from "./routes/state-middleware/_middleware.ts";
|
||||
@@ -85,6 +86,7 @@ import * as $std from "./routes/std.tsx";
|
||||
import * as $umlaut_äöüß from "./routes/umlaut-äöüß.tsx";
|
||||
import * as $wildcard from "./routes/wildcard.tsx";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import * as $DangerousIsland from "./islands/DangerousIsland.tsx";
|
||||
import * as $Foo_Bar from "./islands/Foo.Bar.tsx";
|
||||
import * as $FormIsland from "./islands/FormIsland.tsx";
|
||||
import * as $Greeter from "./islands/Greeter.tsx";
|
||||
@@ -194,6 +196,7 @@ const manifest = {
|
||||
"./routes/route-groups/(foo)/_layout.tsx": $route_groups_foo_layout,
|
||||
"./routes/route-groups/(foo)/index.tsx": $route_groups_foo_index,
|
||||
"./routes/signal_shared.tsx": $signal_shared,
|
||||
"./routes/spoof_state.tsx": $spoof_state,
|
||||
"./routes/state-in-props/_middleware.ts": $state_in_props_middleware,
|
||||
"./routes/state-in-props/index.tsx": $state_in_props_index,
|
||||
"./routes/state-middleware/_middleware.ts": $state_middleware_middleware,
|
||||
@@ -208,6 +211,7 @@ const manifest = {
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
"./islands/DangerousIsland.tsx": $DangerousIsland,
|
||||
"./islands/Foo.Bar.tsx": $Foo_Bar,
|
||||
"./islands/FormIsland.tsx": $FormIsland,
|
||||
"./islands/Greeter.tsx": $Greeter,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
export default function RawIsland(props: { raw: string }) {
|
||||
const [css, set] = useState("");
|
||||
useEffect(() => {
|
||||
set("raw_ready");
|
||||
}, []);
|
||||
|
||||
return <div class={css} dangerouslySetInnerHTML={{ __html: props.raw }} />;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import DangerousIsland from "../islands/DangerousIsland.tsx";
|
||||
|
||||
export default function SerializePrototype() {
|
||||
return <DangerousIsland raw={`<h1 id="__FRSH_STATE">{.invalid.json}</h1>`} />;
|
||||
}
|
||||
Reference in New Issue
Block a user