GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Flight Reply] Don't allow Symbols to be passed to a reply by sebmarkbage · Pull Request #28610 · react/react

[Flight Reply] Don't allow Symbols to be passed to a reply #28610

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.

Sign up for GitHub

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

Merged
sebmarkbage merged 1 commit into react:main from sebmarkbage:lockdownreply
Mar 21, 2024

Uh oh!

There was an error while loading. Please reload this page.

Merged

[Flight Reply] Don't allow Symbols to be passed to a reply #28610

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
bd8f964
Don't allow Symbols to be passed to a reply
sebmarkbage Mar 21, 2024
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

20 changes: 7 additions & 13 deletions 20 packages/react-client/src/ReactFlightReplyClient.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ function serializeTemporaryReferenceID(id: number): string {
return '$T' + id.toString(16);
}

function serializeSymbolReference(name: string): string {
return '$S' + name;
}

function serializeFormDataReference(id: number): string {
// Why K? F is "Function". D is "Date". What else?
return '$K' + id.toString(16);
Expand Down Expand Up @@ -479,18 +475,16 @@ export function processReply(
}

if (typeof value === 'symbol') {
// $FlowFixMe[incompatible-type] `description` might be undefined
const name: string = value.description;
if (Symbol.for(name) !== value) {
if (temporaryReferences === undefined) {
throw new Error(
'Only global symbols received from Symbol.for(...) can be passed to Server Functions. ' +
`The symbol Symbol.for(${
// $FlowFixMe[incompatible-type] `description` might be undefined
value.description
}) cannot be found among global symbols.`,
'Symbols cannot be passed to a Server Function without a ' +
'temporary reference set. Pass a TemporaryReferenceSet to the options.' +
(__DEV__ ? describeObjectForErrorMessage(parent, key) : ''),
);
}
return serializeSymbolReference(name);
return serializeTemporaryReferenceID(
writeTemporaryReference(temporaryReferences, value),
);
}

if (typeof value === 'bigint') {
Expand Down
10 changes: 5 additions & 5 deletions 10 packages/react-client/src/ReactFlightTemporaryReferences.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

interface Reference {}

export opaque type TemporaryReferenceSet = Array<Reference>;
export opaque type TemporaryReferenceSet = Array<Reference | symbol>;

export function createTemporaryReferenceSet(): TemporaryReferenceSet {
return [];
}

export function writeTemporaryReference(
set: TemporaryReferenceSet,
object: Reference,
object: Reference | symbol,
): number {
// We always create a new entry regardless if we've already written the same
// object. This ensures that we always generate a deterministic encoding of
Expand All @@ -27,15 +27,15 @@ export function writeTemporaryReference(
return newId;
}

export function readTemporaryReference(
export function readTemporaryReference<T>(
set: TemporaryReferenceSet,
id: number,
): Reference {
): T {
if (id < 0 || id >= set.length) {
throw new Error(
"The RSC response contained a reference that doesn't exist in the temporary reference set. " +
'Always pass the matching set that was used to create the reply when parsing its response.',
);
}
return set[id];
return (set[id]: any);
}
4 changes: 0 additions & 4 deletions 4 packages/react-server/src/ReactFlightReplyServer.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,6 @@ function parseModelString(
const chunk = getChunk(response, id);
return chunk;
}
case 'S': {
// Symbol
return Symbol.for(value.slice(2));
}
Comment thread

@sebmarkbage sebmarkbage Mar 21, 2024

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is the functional change since it doesn't matter what the client does if you can still fake a payload that includes this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
case 'F': {
// Server Reference
const id = parseInt(value.slice(2), 16);
Expand Down
3 changes: 2 additions & 1 deletion 3 scripts/error-codes/codes.json
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -501,5 +501,6 @@
"513": "Cannot render a Client Context Provider on the Server. Instead, you can export a Client Component wrapper that itself renders a Client Context Provider.",
"514": "Cannot access %s on the server. You cannot dot into a temporary client reference from a server component. You can only pass the value through to the client.",
"515": "Cannot assign to a temporary client reference from a server module.",
"516": "Attempted to call a temporary Client Reference from the server but it is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component."
"516": "Attempted to call a temporary Client Reference from the server but it is on the client. It's not possible to invoke a client function from the server, it can only be rendered as a Component or passed to props of a Client Component.",
"517": "Symbols cannot be passed to a Server Function without a temporary reference set. Pass a TemporaryReferenceSet to the options.%s"
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402809 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.