Skip to content

fix(server): guard invalid JSON in PageBinding.dispatch#41805

Open
SebTardif wants to merge 1 commit into
microsoft:mainfrom
SebTardif:fix/pagebinding-json-parse-guard
Open

fix(server): guard invalid JSON in PageBinding.dispatch#41805
SebTardif wants to merge 1 commit into
microsoft:mainfrom
SebTardif:fix/pagebinding-json-parse-guard

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Summary

PageBinding.dispatch parsed the binding payload with JSON.parse outside the existing try/catch. A malformed payload from the page (or a corrupted protocol message) threw an uncaught SyntaxError and aborted the binding pipeline.

Fix

Parse the payload in a dedicated try/catch. On invalid JSON, log via debugLogger and return. When parse succeeds, the existing try/catch still delivers binding errors to the page with name/seq.

Evidence (red / green)

# Red (before fix)
SyntaxError: Expected property name or '}' in JSON at position 1
  await pageImpl.onBindingCalled('{not-valid-json', context);

# Green (after fix)
1 passed — page continues to evaluate after bad payload
page-expose-function.spec.ts: 22 passed (chromium-page)

Test plan

  • New test: invalid binding payload does not crash
  • Full page-expose-function.spec.ts on chromium-page

JSON.parse(payload) ran outside the try/catch, so a malformed binding
payload from the page crashed the binding pipeline instead of being
logged and ignored.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
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.

1 participant