Fix JSDoc comment security vulnerability: escape only necessary */ sequences#1368
Closed
FDiskas wants to merge 11 commits intoacacode:mainfrom
Closed
Fix JSDoc comment security vulnerability: escape only necessary */ sequences#1368FDiskas wants to merge 11 commits intoacacode:mainfrom
FDiskas wants to merge 11 commits intoacacode:mainfrom
Conversation
Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
- Modified formatDescription() to detect already-escaped content and avoid double-escaping - Ensures */ becomes *\/ (single backslash) instead of *\\/ (double backslash) - Ensures /* becomes \/* (single backslash) instead of \\/* (double backslash) - Maintains security by still escaping dangerous JSDoc characters - All tests pass (128/128) confirming no regressions Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 37bf80a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
Collaborator
|
bugbot run |
…yEscaped check Co-authored-by: FDiskas <468006+FDiskas@users.noreply.github.com>
Author
|
Updated PR |
smorimoto
approved these changes
Aug 28, 2025
Collaborator
|
bugbot run |
| !_.isUndefined(field.pattern) && `@pattern ${escapeJSDocContent(field.pattern)}`, | ||
| !_.isUndefined(field.example) && | ||
| `@example ${_.isObject(field.example) ? JSON.stringify(field.example) : field.example}`, | ||
| `@example ${_.isObject(field.example) ? JSON.stringify(field.example) : escapeJSDocContent(field.example)}`, |
Collaborator
|
See #1611 |
smorimoto
added a commit
that referenced
this pull request
Feb 8, 2026
…1611) OpenAPI spec fields (descriptions, titles, examples, patterns, etc.) are untrusted input that may contain `*/` sequences. When embedded in JSDoc block comments, these sequences prematurely close the comment, producing invalid TypeScript output. Add `escapeJSDocContent()` to SchemaFormatters that replaces `*/` with `*\/` and expose it as a template utility. Apply escaping consistently across all JSDoc-emitting templates (data-contract-jsdoc, object-field-jsdoc, route-docs, api) and enum field descriptions. Closes #1321 Closes #672 Closes #704 Supersedes #1368
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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:
Generated vulnerable output:
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:
Technical Details
escapeJSDocContent()insrc/schema-parser/schema-formatters.tsto only escape*/route-docs.ejsto use consistent escaping approachformatDescription()detects already-escaped content to prevent double-escapingImpact
\/*in docs)