Fix JSDoc comment security vulnerability: escape only necessary */ sequences
vibe coded PR
closes #1321
This PR fixes a security vulnerability where unescaped characters in OpenAPI/Swagger descriptions could break generated TypeScript files or enable code injection attacks. The fix uses minimal escaping - only escaping the dangerous */ sequences while leaving harmless /* sequences unescaped to reduce noise in generated documentation.
Problem
Vulnerable input example:
description: "This endpoint is equivalent to **/information** endpoint"
summary: "Get data with **/ alert('XSS') /** injection attempt"
Generated vulnerable output:
/**
* Description with */ alert('XSS') /* injection attempt
*/
The */ sequence breaks out of the JSDoc comment, allowing arbitrary JavaScript code execution.
Solution
The fix applies surgical escaping that only targets the dangerous pattern:
*/sequences are escaped to*\/(prevents comment breakout)/*sequences remain unescaped (harmless inside comments)
Safe output after fix:
/**
* Description with *\/ alert('XSS') /* injection attempt
*/
Technical Details
- Core changes: Updated
escapeJSDocContent()insrc/schema-parser/schema-formatters.tsto only escape*/ - Template consistency: Modified
route-docs.ejsto use consistent escaping approach - Smart detection:
formatDescription()detects already-escaped content to prevent double-escaping - Fixed snapshots: Corrected test snapshots to show proper single backslash escaping
Impact
- Security: Prevents code injection through OpenAPI documentation fields
- Clean output: Reduces unnecessary escaping noise (no more
\/*in docs) - Compatibility: No breaking changes to existing functionality
🦋 Changeset detected
Latest commit: 37bf80a8c9421ed50a2ebf053c8a635d7bb16b21
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| swagger-typescript-api | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
bugbot run
Updated PR
bugbot run