fix: address code quality and security issues from CodeQL scanning#29
fix: address code quality and security issues from CodeQL scanning#29
Conversation
…ation safety Addresses CodeQL alert #16 (js/unsafe-code-construction) Changes: - Add detailed JSDoc warnings to Mapper class about dynamic code generation - Document Mapper.create() method with security guidelines and examples - Add security warnings to getCompiledFn() method - Enhance SECURITY.md with dynamic code generation security section - Provide safe vs unsafe usage examples - Recommend Decorator API as the safest approach The use of new Function() is intentional for performance optimization (112-474% faster). This is safe when mapping configurations come from trusted sources (developer-defined code), which is the intended usage. The documentation now clearly warns developers to NEVER use user-controlled data as mapping configuration to prevent code injection attacks. Related: #28 CWE-94, CWE-79, CWE-116
Addresses CodeQL alerts #17, #18, #26, #30, #33, #34, #35, #36, #37 Changes: - Remove unused imports from test files: - high-priority-validators.test.ts: IsBase64, IsJWT, IsMACAddress, IsPort, IsStrongPassword, validateSync - complex-combinations.test.ts: Max, validateSync - branch-coverage-boost.test.ts: ArrayMaxSize, ArrayMinSize, IsDateString, IsIn, IsPort, IsURL, IsUUID, MaxLength - memory-leak.test.ts: beforeEach - validation-and-mapping.test.ts: IsNotEmpty, MaxLength - phase2-validators.test.ts: IsNegative, IsPositive - Remove unused imports from example files: - examples/02-advanced/error-handling/complex.ts: MappingConfiguration - examples/01-basic/nested-mapping/index.ts: MappingConfiguration Benefits: - Improved code maintainability - Reduced bundle size - Cleaner codebase - All tests passing with 95.08% coverage Related: #28
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
✅ Code Coverage CheckStatus: PASSED - Coverage Maintained Coverage Comparison
✅ Great Job!\n\nCode coverage has been maintained or improved. This PR is ready for review.Coverage protection is enabled. PRs that decrease coverage will be blocked from merging. |
✅ ESM Build ValidationStatus: All ESM validation checks passed! Test Matrix Results
Validation Steps
What This ValidatesThe ESM validation suite ensures:
✅ The package is ready for ESM consumption! This validation prevents issues like missing |
🚀 Performance Benchmark Results📦 class-transformer Compatibility📊 Performance Comparison Summary📋 Full class-transformer Benchmark Output✅ class-validator Compatibility📋 Full class-validator Benchmark Output🎯 Core Performance⚡ Simple Mapping Benchmark🔧 Complex Transformations Benchmark💡 Note: These are absolute performance numbers from this PR. Benchmarked with Benchmark.js on Node.js 20 • View History |
## [4.2.1](v4.2.0...v4.2.1) (2025-10-16) ### Bug Fixes * address code quality and security issues from CodeQL scanning ([#29](#29)) ([bb1cdad](bb1cdad)), closes [#16](#16) [#17](#17) [#18](#18) [#26](#26) [#30](#30) [#33](#33) [#34](#34) [#35](#35) [#36](#36) [#37](https://github.com/Isqanderm/data-mapper/issues/37) [#28](#28)
|
🎉 This PR is included in version 4.2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
This PR addresses all code quality and security issues identified by GitHub's CodeQL code scanning.
Changes
🔴 Security Issue Fixed (Alert #16)
Issue: Unsafe code constructed from library input (CWE-94, CWE-79, CWE-116)
src/core/Mapper.ts:281Fix Applied:
Mapperclass warning about dynamic code generationMapper.create()method with safe/unsafe usage examplesgetCompiledFn()methodSECURITY.mdwith dynamic code generation security sectionRationale: The use of
new Function()is intentional for performance optimization (112-474% faster). This is safe when mapping configurations come from trusted sources (developer-defined code), which is the intended usage. The documentation now clearly warns developers to NEVER use user-controlled data as mapping configuration.🟡 Code Quality Issues Fixed (Alerts #17, #18, #26, #30, #33, #34, #35, #36, #37)
Issue: Unused imports in test files and examples
Files Fixed:
tests/unit/compat/class-validator/high-priority-validators.test.tstests/unit/compat/class-validator/complex-combinations.test.tstests/unit/compat/class-validator/branch-coverage-boost.test.tstests/benchmarks/memory-leak.test.tstests/unit/integration/validation-and-mapping.test.tstests/unit/compat/class-validator/phase2-validators.test.tsexamples/02-advanced/error-handling/complex.tsexamples/01-basic/nested-mapping/index.tsRemoved Imports:
IsBase64,IsJWT,IsMACAddress,IsPort,IsStrongPassword,validateSync,Max,ArrayMaxSize,ArrayMinSize,IsDateString,IsIn,IsURL,IsUUID,MaxLength,beforeEach,IsNotEmpty,IsNegative,IsPositiveMappingConfiguration(2 occurrences)Testing
✅ All tests passing: 518 tests passed
✅ Code coverage maintained: 95.08%
✅ No breaking changes
Security Considerations
The security warning (Alert #16) has been addressed through comprehensive documentation rather than code changes because:
Benefits
Closes
Closes #28
CodeQL Alerts Addressed
Checklist
Pull Request opened by Augment Code with guidance from the PR author