Fix realpath vulnerability and hardcoded file input#1
Fix realpath vulnerability and hardcoded file input#1
Conversation
…rabilities Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
- Replaced ambiguous "Invalid file path" with "Invalid upload folder" - Improves debugging and error semantics Compliance: - No logic changes - No breaking changes - Message clarity improved Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
…uation - Added exit immediately after Location header - Prevents execution of unintended code after redirect - Ensures correct HTTP response behavior Compliance: - No logic changes - No breaking changes - Critical flow control fix applied Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
…re random_bytes - Replaced uniqid() with bin2hex(random_bytes(16)) - Prevents predictable filename generation - Improves security against file enumeration attacks Compliance: - No breaking changes - Security enhancement applied Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
…sitory - Removed all @ operators from file and IO functions - Prevents hidden runtime errors - Improves debugging and observability across the codebase Compliance: - No logic changes - No breaking changes - Repository-wide cleanup applied Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
- Removed manual folder creation from tests - Ensures realpath() failure scenarios are properly tested - Aligns tests with real production behavior Compliance: - No production changes - Test reliability improved Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
- Added test case where upload directory already exists - Ensures upload logic works in both creation and pre-existing states - Improves test coverage completeness Compliance: - No production changes - Test coverage expanded Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
…position - Analyzed current class responsibilities - Proposed separation into independent services - Prepared foundation for future refactor Compliance: - No code changes - Planning phase only Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
- Added LocalFilesystem service for file operations - Added FileValidator service for validation logic - Prepared UploadBase for composition-based architecture - No breaking changes Compliance: - Backward compatibility preserved - Phase 1 of refactor completed Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
…phase 2) - Moved folder creation logic to LocalFilesystem - Delegated file moving operations - UploadBase now acts as orchestrator - No breaking changes Compliance: - Backward compatibility preserved - Phase 2 refactor applied Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
This commit resolves critical security issues found during the library audit:
realpath()bypass vulnerability: The file upload path validation logic was flawed because it checkedrealpath()before creating the destination directory. If the directory didn't exist,realpath()returnedfalse, which was cast to an empty string, allowing the validation to pass and potentially write to the system root. This is fixed by callingcreateUploadFolder()before checkingrealpath(), and explicitly failing ifrealpath()still returnsfalse.$_FILES["file"]: The library previously hardcoded checks against the"file"input name, preventing its use with other input names. This is addressed by introducing a configurable$file_input_nameproperty, defaulting to"file"for backward compatibility, and adding asetFileInputName()setter.PR created automatically by Jules for task 990044285235341142 started by @Maatify