feat: add comprehensive security validation and documentation to sitemap-xml #457
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.
Summary
This PR enhances the security and code quality of
lib/sitemap-xml.tsthrough comprehensive validation, improved XML entity escaping, and detailed documentation.Security Improvements
π Enhanced XML Entity Escaping
>character escaping (>) totext()function for defense-in-depth&,<,>&,<,>,",'π‘οΈ Attribute Name Validation
validateAttributeName()function prevents injection via malformed attribute namesInvalidXMLAttributeNameError<script>)π Type Safety
text,otag,ctag,element)TypeErrorfor non-string inputsCode Quality Improvements
π Comprehensive Documentation
β Test Coverage
Breaking Changes
These are defensive breaking changes that improve security:
otag()throwsInvalidXMLAttributeNameErrorfor invalid attribute namesTypeErrorfor non-string inputs>character (outputs>)Test Results
Files Changed
lib/sitemap-xml.ts- Complete rewrite with security enhancements and documentationlib/errors.ts- AddedInvalidXMLAttributeNameErrorclasstests/sitemap-xml.test.ts- Comprehensive test suite expansiontests/mocks/generator.ts- Updated test fixtures for new escapingtests/sitemap-item-stream.test.ts- Updated one attribute escape sequenceRelated Issues
Addresses security audit requirements for XML generation code.
π€ Generated with Claude Code