Skip to content

fix(subtitles): harden subtitle rendering against xss#1926

Merged
gemxx merged 1 commit into
mainfrom
codex/subtitle-xss-hardening
Jun 8, 2026
Merged

fix(subtitles): harden subtitle rendering against xss#1926
gemxx merged 1 commit into
mainfrom
codex/subtitle-xss-hardening

Conversation

@gemxx

@gemxx gemxx commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@gemxx gemxx added this to the v3.0.25 milestone Jun 8, 2026
@gemxx gemxx requested a review from Copilot June 8, 2026 06:42
@gemxx gemxx self-assigned this Jun 8, 2026
@gemxx gemxx added the subtitles label Jun 8, 2026
@gemxx gemxx requested a review from xiong-001 June 8, 2026 06:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens xgplayer-subtitles rendering to prevent DOM XSS by eliminating direct innerHTML insertion and introducing a whitelist-based inline-markup renderer for subtitles.

Changes:

  • Added a safe inline subtitle renderer that only materializes allowlisted tags/attributes into DOM nodes.
  • Updated subtitle parsing/encoding and the runtime renderer to route all subtitle text through the safe renderer (and to strip markup for word-by-word rendering).
  • Added Jest coverage for XSS cases and refreshed the subtitle demo fixtures to include an XSS validation track and UI.

Reviewed changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/xgplayer-subtitles/src/xss/safeInlineTags.js Defines allowlisted inline/void tag names and normalization helpers.
packages/xgplayer-subtitles/src/xss/safeInlineRenderer.js Implements safe parsing + DOM construction for inline subtitle markup.
packages/xgplayer-subtitles/src/parser.js Encodes subtitle text to prevent raw HTML injection; avoids mis-classifying safe inline tags as language wrappers.
packages/xgplayer-subtitles/src/index.js Replaces innerHTML rendering with appendSubtitleText(); strips markup before splitWords().
packages/xgplayer-subtitles/README.md Documents the new safe rendering behavior and supported tags.
packages/xgplayer-subtitles/tests/xss.spec.js Adds automated tests asserting XSS payloads remain inert and allowlisted markup renders safely.
jest.config.js Includes xgplayer-subtitles test glob in Jest’s testMatch.
fixtures/subtitle/shared/utils.js Demo helpers for decoding/formatting subtitle cue text and checking for unsafe nodes.
fixtures/subtitle/shared/tracks.js Demo tracks including a dedicated XSS test track and cases.
fixtures/subtitle/shared/timeline.js Timeline UI component for the demo (inert text rendering).
fixtures/subtitle/index.js Reworked demo logic/UI wiring for track switching + XSS status reporting.
fixtures/subtitle/index.html Updated demo UI/markup/styles for the new controls, timeline, and status panel.
.gitignore Un-ignores shared fixture JS helpers so the new demo modules are tracked.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 380 to 382
// 动态构造语言匹配规则
// eslint-disable-next-line no-useless-escape
const newReg = RegExp(`^<${tag}>(([\\s\\S])*?)<\/${tag}>$`)
@gemxx gemxx merged commit 4c0f96a into main Jun 8, 2026
5 checks passed
@gemxx gemxx deleted the codex/subtitle-xss-hardening branch June 8, 2026 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants