fiber icon indicating copy to clipboard operation
fiber copied to clipboard

🐛 bug: align upload root config

Open gaby opened this issue 1 month ago • 5 comments

Summary

  • This pull request enhances the security of file upload operations by introducing configurable upload root directory management and comprehensive path validation. The changes prevent directory traversal, absolute path exploits, and symlink-based attacks by validating all upload paths against a configured root directory before allowing file writes.

Key Changes:

  • Added three new configuration options: RootDir (upload root directory), RootFS (filesystem implementation for validation), and RootPerms (permissions for root directory creation)
  • Implemented multi-layer path validation in SaveFile and SaveFileToStorage methods that rejects absolute paths, directory traversal attempts, and symlink escapes Added comprehensive test coverage for security scenarios including traversal prevention and absolute path rejection

gaby avatar Dec 10 '25 05:12 gaby

[!IMPORTANT]

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

[!NOTE]

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch add-path-normalization-and-validation-to-savefile

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 10 '25 05:12 coderabbitai[bot]

Summary of Changes

Hello @gaby, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security and configurability of the file upload mechanism. It introduces dedicated configuration options for defining the root directory, file system, and permissions for uploads, alongside implementing comprehensive path validation to prevent common security vulnerabilities such as directory traversal and symlink attacks. The changes ensure that all file uploads are strictly confined to the intended root directory, improving the overall robustness of the application's file handling.

Highlights

  • Upload Configuration Renamed and Enhanced: The upload configuration fields have been renamed to RootDir and RootFS, and a new RootPerms field has been added to allow configurable default permissions for the upload root directory.
  • Secure Upload Path Resolution: The logic for resolving upload paths has been centralized and updated to use the new configuration, shared path trimming helpers, and a set of new, specific error definitions. This includes robust validation against absolute paths, directory traversal, and symlink escapes.
  • Updated Tests and Documentation: Upload-related tests have been adjusted to reflect the new configuration names and path validation. The API documentation and 'What's New' guide have been updated to clearly document the new upload root requirements and security features.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist[bot] avatar Dec 10 '25 05:12 gemini-code-assist[bot]

Codecov Report

:x: Patch coverage is 60.57692% with 41 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 91.34%. Comparing base (26e8e8a) to head (b550622). :warning: Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
ctx.go 59.00% 22 Missing and 19 partials :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3934      +/-   ##
==========================================
- Coverage   91.56%   91.34%   -0.23%     
==========================================
  Files         119      119              
  Lines       10165    10266     +101     
==========================================
+ Hits         9308     9377      +69     
- Misses        544      560      +16     
- Partials      313      329      +16     
Flag Coverage Δ
unittests 91.34% <60.57%> (-0.23%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Dec 10 '25 05:12 codecov[bot]

/gemini review

gaby avatar Dec 10 '25 14:12 gaby

@codex review

gaby avatar Dec 10 '25 14:12 gaby