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:
@@ -117,9 +117,12 @@ import * as $relative_link_index from "./routes/relative_link/index.tsx";
|
||||
import * as $scroll_restoration_index from "./routes/scroll_restoration/index.tsx";
|
||||
import * as $scroll_restoration_injected from "./routes/scroll_restoration/injected.tsx";
|
||||
import * as $scroll_restoration_update from "./routes/scroll_restoration/update.tsx";
|
||||
import * as $spoof_state_index from "./routes/spoof_state/index.tsx";
|
||||
import * as $spoof_state_partial from "./routes/spoof_state/partial.tsx";
|
||||
import * as $Counter from "./islands/Counter.tsx";
|
||||
import * as $CounterA from "./islands/CounterA.tsx";
|
||||
import * as $CounterB from "./islands/CounterB.tsx";
|
||||
import * as $DangerousIsland from "./islands/DangerousIsland.tsx";
|
||||
import * as $Fader from "./islands/Fader.tsx";
|
||||
import * as $InvalidSlot from "./islands/InvalidSlot.tsx";
|
||||
import * as $KeyExplorer from "./islands/KeyExplorer.tsx";
|
||||
@@ -262,11 +265,14 @@ const manifest = {
|
||||
"./routes/scroll_restoration/index.tsx": $scroll_restoration_index,
|
||||
"./routes/scroll_restoration/injected.tsx": $scroll_restoration_injected,
|
||||
"./routes/scroll_restoration/update.tsx": $scroll_restoration_update,
|
||||
"./routes/spoof_state/index.tsx": $spoof_state_index,
|
||||
"./routes/spoof_state/partial.tsx": $spoof_state_partial,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Counter.tsx": $Counter,
|
||||
"./islands/CounterA.tsx": $CounterA,
|
||||
"./islands/CounterB.tsx": $CounterB,
|
||||
"./islands/DangerousIsland.tsx": $DangerousIsland,
|
||||
"./islands/Fader.tsx": $Fader,
|
||||
"./islands/InvalidSlot.tsx": $InvalidSlot,
|
||||
"./islands/KeyExplorer.tsx": $KeyExplorer,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
export default function DangerousIsland(props: { raw: string }) {
|
||||
const [css, set] = useState("");
|
||||
useEffect(() => {
|
||||
set("raw_ready");
|
||||
}, []);
|
||||
|
||||
return <div class={css} dangerouslySetInnerHTML={{ __html: props.raw }} />;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Partial } from "$fresh/runtime.ts";
|
||||
|
||||
export default function SerializePrototype() {
|
||||
return (
|
||||
<div>
|
||||
<Partial name="content">
|
||||
<p>initial</p>
|
||||
</Partial>
|
||||
<a href="/spoof_state/partial">Update</a>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Partial } from "$fresh/runtime.ts";
|
||||
import DangerousIsland from "../../islands/DangerousIsland.tsx";
|
||||
|
||||
export default function Res() {
|
||||
return (
|
||||
<Partial name="content">
|
||||
<DangerousIsland raw={`<h1 id="__FRSH_STATE">{.invalid.json}</h1>`} />
|
||||
<p class="done">partial</p>
|
||||
</Partial>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user