Improve error handling and security#101
Merged
dereuromark merged 2 commits intomasterfrom Mar 23, 2026
Merged
Conversation
Security: - Add callable whitelist for transform functions to prevent arbitrary code execution - Block unsafe functions like system, exec, passthru from being used as transformers - Allow only whitelisted safe functions and static class methods Error handling: - Pattern validation now catches invalid regex and throws clear InvalidArgumentException - Factory return type validation ensures factories return expected types - Collection count() errors are now properly caught and wrapped - File operations have proper error handling with helpful messages - JSON parsing errors include source context Path security: - Validate target paths stay within expected directories - Check for null bytes and path traversal sequences - Use realpath() to verify directory boundaries Error message improvements: - Required field messages include class name for easier debugging - Single vs plural error messages for better readability - Multi-line formatting for multiple validation errors Tests: - Add test for blocked unsafe callable - Update validation test for new error message format - Add tests for error message formatting
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #101 +/- ##
============================================
- Coverage 83.09% 82.46% -0.64%
- Complexity 1447 1465 +18
============================================
Files 42 42
Lines 3543 3615 +72
============================================
+ Hits 2944 2981 +37
- Misses 599 634 +35 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
Comprehensive security and error handling improvements based on deep dive code audit.
Security
Callable Whitelist:
system,exec,passthrufrom being used intransformFrom/transformToClass::method) are still allowed for custom transformationsPath Traversal Protection:
..sequences in DTO namesrealpath()to verify directory boundariesError Handling
Pattern Validation:
InvalidArgumentExceptionwith the pattern and field namepreg_last_errorand exceptions from the regex engineFactory Return Type:
Collection Count:
count()calls on Countable collections in try-catchFile Operations:
mkdir()andfile_put_contents()@error suppression, uses explicit checks insteadError Message Improvements
Tests