Skip to content

Validate voice and prosody options before building SSML - #5

Merged
arnelirobles merged 2 commits into
mainfrom
fix/2-ssml-injection
Nov 12, 2026
Merged

arnelirobles merged 2 commits into
mainfrom
fix/2-ssml-injection

Conversation

@arnelirobles

@arnelirobles arnelirobles commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Voice, rate, pitch and volume are now checked before they go into the SSML, so a quote can no longer close the attribute and inject SSML. A bad value throws InvalidOptionError, and both handlers answer 400 for it, and bad host defaults throw when the handler is created. Tests use node:test against the built output, with a new CI step.

Closes #2

- test: test/ssml-injection.test.mjs
  breaks: src/server/edge-tts.ts "checkOption(\"rate\", rate, PROSODY_RE);"
- test: test/ssml-injection.test.mjs
  breaks: src/server/edge-tts.ts "checkOption(\"voice\", voice, VOICE_RE);"
- test: test/ssml-injection.test.mjs
  breaks: src/server/handler.ts "err instanceof InvalidOptionError ? 400 : 500"
- test: test/ssml-injection.test.mjs
  breaks: src/server/handler.ts "checkDefaults(opts);"
- test: test/ssml-injection.test.mjs
  breaks: src/server/handler.ts "err instanceof InvalidOptionError ? 400 : 500"
- untested: src/server.ts #1
  why: export line only, exposes buildSsml, assertOptions and InvalidOptionError
- untested: README.md #1
  why: docs only
- untested: package.json #1
  why: adds the test script
- untested: .github/workflows/ci.yml #1
  why: adds the CI test step

Summary by CodeRabbit

  • New Features

    • Added validation for voice, rate, pitch, and volume options. Invalid values now return a 400 response, including when supplied as handler defaults.
    • Added public exports for option validation and SSML building utilities.
  • Tests

    • Added automated tests for invalid options, handler responses, and valid SSML values.
    • The test suite now runs as part of CI.
  • Documentation

    • Updated the endpoint response reference to include additional reasons for a 400 response.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

SSML option values are validated before synthesis. Both handler types validate configured defaults and return HTTP 400 for invalid options. Tests cover rejection, valid SSML construction, text escaping, and handler responses.

Changes: SSML Option Validation

Layer / File(s) Summary
Validate and build SSML
src/server.ts, src/server/edge-tts.ts, test/ssml-injection.test.mjs
The server entry point exports InvalidOptionError, assertOptions, and buildSsml. buildSsml validates voice and prosody values, escapes text, and constructs SSML. EdgeTTS.synthesize builds SSML before WebSocket setup. Tests cover invalid attributes and valid SSML construction.
Validate handler defaults and requests
src/server/handler.ts, test/ssml-injection.test.mjs, README.md, package.json, .github/workflows/ci.yml
Both handler factories validate configured defaults. Fetch and Express/Connect handlers return status 400 for InvalidOptionError. Tests cover handler responses and defaults. The README lists invalid options as 400-response conditions, and the package and CI workflows run the tests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 90609

The change validates voice, rate, pitch and volume before building SSML, and both handlers return 400 for invalid options. This closes the injection path described in the linked issue. No concrete merge-blocking risk remains. Symbolic prosody values such as "slow" are now rejected, but the repository does not document them as supported.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Validate voice and prosody options before building SSML" matches the main change. The PR adds an InvalidOptionError class, validation for voice, rate, pitch, and volume, and handler 400 res…
Linked Issues check Passed Issue #2 requires that voice, rate, pitch and volume be validated or escaped before SSML construction, so a quote-containing rate never appears raw in an attribute. At the reviewed head, `src/server/e…
Out of Scope Changes check Passed The whole-PR diff (merge base 78cb3bd to head 9060916) changes these areas: option validation and buildSsml in src/server/edge-tts.ts; 400 mapping and checkDefaults in src/server/handler.ts; r…
Full details: Title check

Explanation

The title "Validate voice and prosody options before building SSML" matches the main change. The PR adds an InvalidOptionError class, validation for voice, rate, pitch, and volume, and handler 400 responses. The changeset validates these options in edge-tts.ts and buildSsml before SSML is built, so the title states the primary change accurately.

Full details: Linked Issues check

Explanation

Issue #2 requires that voice, rate, pitch and volume be validated or escaped before SSML construction, so a quote-containing rate never appears raw in an attribute. At the reviewed head, src/server/edge-tts.ts defines VOICE_RE (^[A-Za-z0-9]+(-[A-Za-z0-9]+)+$) and PROSODY_RE (^(default|[+-]?\d+(\.\d+)?(%|Hz|st)?)$). buildSsml calls checkOption on all four values before it builds the SSML string, and checkOption throws InvalidOptionError on any mismatch. Neither regex admits quotes, angle brackets, or spaces, so the 100%'><break .../> payload from the issue is rejected. EdgeTTS.synthesize calls buildSsml before it opens the WebSocket, so the raw attribute interpolation is gone. The request path in src/server/handler.ts passes body.rate, body.pitch, body.volume and body.voice into synthesize, so the check covers request input. Both handler factories map InvalidOptionError to HTTP 400, which matches the PR description. checkDefaults runs at factory creation, so invalid host defaults fail at setup. The issue's separate timeout request is out of scope and is not required. I did not read test/ssml-injection.test.mjs. The PASS rests on the source code, not on the test coverage.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff (merge base 78cb3bd to head 9060916) changes these areas: option validation and buildSsml in src/server/edge-tts.ts; 400 mapping and checkDefaults in src/server/handler.ts; re-exports in src/server.ts; the new test file; package.json (test script); the CI test step; and a README table row. The validation, handler, and test changes implement issue #2. The src/server.ts re-exports of InvalidOptionError, assertOptions, and buildSsml expose the new validation API. The package.json and CI changes add the node --test run that the tests need. The README row documents the new 400 cases. The reordering of SSML construction ahead of the WebSocket open is a supporting change for the validation. No change is unrelated to issue #2. The issue's timeout suggestion is not implemented, which is correct because it is out of scope.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f5c11584-355f-49a8-9ce0-ae3fe928ca03
Commits

Reviewing files that changed from the base of the PR and between 78cb3bd and 9060916.

Files selected for processing: 7

  • .github/workflows/ci.yml
  • README.md
  • package.json
  • src/server.ts
  • src/server/edge-tts.ts
  • src/server/handler.ts
  • test/ssml-injection.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@arnelirobles
arnelirobles marked this pull request as ready for review November 12, 2026 12:45
@arnelirobles
arnelirobles merged commit c2f85bd into main Nov 12, 2026
3 checks passed
@arnelirobles
arnelirobles deleted the fix/2-ssml-injection branch November 12, 2026 13:06
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.

SSML injection through unvalidated rate, pitch, volume and voice

1 participant