Apply security fixes to asciinema-player.js: Add origin validation and fix regex escape sequence #134
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.
Overview
This PR applies two important security and correctness fixes to
docs/assets/js/asciinema-player.js.Changes
1. Add Origin Validation for postMessage Events (Line 148-150)
Added origin validation to the message event listener to prevent potential cross-origin security vulnerabilities. The change introduces a
trustedOriginsarray and validates that incoming messages originate from trusted sources before processing them.Before:
After:
This prevents malicious sites from sending messages that could be processed by the player.
2. Fix Regex Escape Sequence in Ni Function (Line 19506)
Corrected the regular expression pattern to properly escape both backslash and double quote characters. The regex was missing a backslash escape for the double quote character.
Before:
After:
This ensures the regex correctly matches and escapes double quote characters in strings.
Impact
Testing
Both changes are surgical modifications to existing minified code and maintain backward compatibility while improving security and correctness.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.