Skip to content

Fix realpath vulnerability and hardcoded file input#1

Open
Maatify wants to merge 10 commits intomasterfrom
jules-fix-realpath-vulnerability-990044285235341142
Open

Fix realpath vulnerability and hardcoded file input#1
Maatify wants to merge 10 commits intomasterfrom
jules-fix-realpath-vulnerability-990044285235341142

Conversation

@Maatify
Copy link
Copy Markdown
Owner

@Maatify Maatify commented Mar 27, 2026

This commit resolves critical security issues found during the library audit:

  1. realpath() bypass vulnerability: The file upload path validation logic was flawed because it checked realpath() before creating the destination directory. If the directory didn't exist, realpath() returned false, which was cast to an empty string, allowing the validation to pass and potentially write to the system root. This is fixed by calling createUploadFolder() before checking realpath(), and explicitly failing if realpath() still returns false.
  2. Hardcoded $_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_name property, defaulting to "file" for backward compatibility, and adding a setFileInputName() setter.

PR created automatically by Jules for task 990044285235341142 started by @Maatify

…rabilities

Co-authored-by: Maatify <130119162+Maatify@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

google-labs-jules bot and others added 9 commits March 27, 2026 22:49
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant