8000 Fix file tokens not working on file-security by ItzNotABug · Pull Request #10120 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix file tokens not working on file-security #10120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 8, 2025
Merged

Conversation

ItzNotABug
Copy link
Member
@ItzNotABug ItzNotABug commented Jul 8, 2025

What does this PR do?

Fixes an issue with file tokens not working when file security was enabled on bucket.

Test Plan

Manual.

Screen.Recording.2025-07-08.at.2.31.54.PM.mov

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@ItzNotABug ItzNotABug self-assigned this Jul 8, 2025
Copy link
coderabbitai bot commented Jul 8, 2025
📝 Walkthrough

"""

Walkthrough

The changes introduce PHPDoc-style type annotations for variables representing storage buckets and files in the storage API controller, clarifying their expected types. Conditional checks for file access are updated to include an additional token-based access condition. In a shared API controller, an unused variable assignment is removed, simplifying the code without affecting functionality. Additionally, a single blank line is added for readability in a file action handler after an exception check. A new end-to-end test method is added to verify downloading files with file-level security using tokens. No function signatures or public entity declarations are altered.

Possibly related issues

Possibly related PRs

  • Feat: tokens #8997: This PR introduces token management endpoints and integrates token authorization in storage access, closely related to the current PR’s updates on token-based access checks and type annotations in storage controllers.

Suggested reviewers

  • lohanidamodar
  • Meldiron
    """

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97d5f0f and 7ca951e.

📒 Files selected for processing (1)
  • tests/e2e/Services/Tokens/TokensBase.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/e2e/Services/Tokens/TokensBase.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Benchmark
  • GitHub Check: Linter
  • GitHub Check: scan
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
github-actions bot commented Jul 8, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
pyc 3.12.9-r0 CVE-2024-12718 HIGH
pyc 3.12.9-r0 CVE-2025-4138 HIGH
pyc 3.12.9-r0 CVE-2025-4330 HIGH
pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3 3.12.9-r0 CVE-2024-12718 HIGH
python3 3.12.9-r0 CVE-2025-4138 HIGH
python3 3.12.9-r0 CVE-2025-4330 HIGH
python3 3.12.9-r0 CVE-2025-4517 HIGH
python3-pyc 3.12.9-r0 CVE-2024-12718 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4138 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4330 HIGH
python3-pyc 3.12.9-r0 CVE-2025-4517 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2024-12718 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4138 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4330 HIGH
python3-pycache-pyc0 3.12.9-r0 CVE-2025-4517 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/controllers/api/storage.php (2)

970-971: Use the standard @var PHPDoc tag instead of the non-standard @type

Static analysers (Psalm, PHPStan) and IDEs recognise the /** @var … */ annotation; /* @type … */ is ignored, so you lose the type-hinting benefit you are aiming for.

-        /* @type Document $bucket */
+        /** @var Document $bucket */

-            /* @type Document $file */
+            /** @var Document $file */

Apply the same replacement to every @type occurrence added in this PR (preview, download, view actions).

Also applies to: 1162-1164, 1183-1185, 1323-1325, 1345-1346


980-988: Token bypass condition looks correct – just confirm coverage

The new $isToken flag is now part of all auth shortcuts:

if (!$fileSecurity && !$valid && !$isToken) { … }

and

if ($fileSecurity && !$valid && !$isToken) { … }

That should let a valid resource token access a private bucket / file while still blocking everyone else – nice.

Please ensure there are integration tests for:

  1. valid token + no read permission → allowed
  2. invalid token + no read permission → USER_UNAUTHORIZED

Happy to scaffold Behat/Pest tests if needed.

Also applies to: 1172-1180, 1333-1341

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between edd7a4a and 14e5205.

📒 Files selected for processing (3)
  • app/controllers/api/storage.php (6 hunks)
  • app/controllers/shared/api.php (0 hunks)
  • src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php (1 hunks)
💤 Files with no reviewable changes (1)
  • app/controllers/shared/api.php
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/controllers/api/storage.php (1)
src/Appwrite/Event/Database.php (1)
  • getDocument (107-110)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (1)
src/Appwrite/Platform/Modules/Tokens/Http/Tokens/Buckets/Files/Action.php (1)

37-42: No-op change – nothing to review

Only an extra blank line was introduced after the STORAGE_FILE_NOT_FOUND guard.
Behaviour, readability and PSR-12 compliance remain intact.

Copy link
github-actions bot commented Jul 8, 2025

✨ Benchmark results

  • Requests per second: 942
  • Requests with 200 status code: 169,632
  • P99 latency: 0.199046918

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 942 1,118
200 169,632 201,249
P99 0.199046918 0.170346771

Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14e5205 and 97d5f0f.

📒 Files selected for processing (1)
  • tests/e2e/Services/Tokens/TokensBase.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Benchmark
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (1)
tests/e2e/Services/Tokens/TokensBase.php (1)

278-278: LGTM: Blank line improves readability.

The blank line addition helps separate the test methods for better readability.

@Meldiron Meldiron merged commit 6d321f6 into 1.7.x Jul 8, 2025
38 checks passed
@ItzNotABug ItzNotABug deleted the fix-file-tokens branch July 8, 2025 11:45
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.

3 participants
0