Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: __FRSH_STATE potentially being overwritten by user code #2256

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

marvinhagemeister
Copy link
Collaborator

@marvinhagemeister marvinhagemeister commented Jan 15, 2024

As outlined in #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>

Copy link
Member

@lucacasonato lucacasonato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marvinhagemeister marvinhagemeister merged commit 9f81806 into main Jan 15, 2024
12 checks passed
@marvinhagemeister marvinhagemeister deleted the sec-fixes branch January 15, 2024 18:41
@guitavano
Copy link

To share the apprenticeship, at deco.cx we use __FRSH_STATE to see how much data is going to client side

image

After that, a small adjustment was necessary:

document.getElementById("__FRSH_STATE")?.textContent
to
document.querySelector("script[id^='__FRSH_STATE']")?.textContent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants