Skip to content

fix(api): restore accessible check on document preview - #15505

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
kiannidev:fix/15501-preview-accessible
Jun 4, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
kiannidev:fix/15501-preview-accessible

Conversation

@kiannidev

Copy link
Copy Markdown
Contributor

Restore DocumentService.accessible on GET /api/v1/documents/{doc_id}/preview so cross-tenant users cannot stream documents by UUID.

Fixes #15501

What problem does this PR solve?

PR #15146 (71a52d579) moved the agent attachment download route and accidentally removed the DocumentService.accessible(doc_id, current_user.id) guard from the REST preview handler. The endpoint still requires login, but any authenticated user who knows another tenant's doc_id can download the raw file bytes.

This restores the same authorization check that existed before #15146, returning a generic "Document not found!" when access is denied (no cross-tenant ID enumeration). SDK download routes tracked in #15125 are unchanged.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

Re-add DocumentService.accessible removed in infiniflow#15146 so
GET /documents/{doc_id}/preview cannot leak cross-tenant files.

Fixes infiniflow#15501
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 2, 2026
@coderabbitai

coderabbitai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8359fac2-0048-4679-8989-425715f75810

📥 Commits

Reviewing files that changed from the base of the PR and between b340aef and dee365b.

📒 Files selected for processing (1)
  • api/apps/restful_apis/document_api.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/apps/restful_apis/document_api.py

📝 Walkthrough

Walkthrough

The PR restores a missing authorization check in the document preview endpoint (GET /documents/<doc_id>/preview) by importing current_user and calling DocumentService.accessible(doc_id, current_user.id) to verify tenant access before returning document storage data.

Changes

Document Preview Authorization Fix

Layer / File(s) Summary
Add authorization check to preview endpoint
api/apps/restful_apis/document_api.py
Import current_user and add an early DocumentService.accessible(doc_id, current_user.id) check in the /documents/<doc_id>/preview handler; return the generic "Document not found!" when access is denied before fetching storage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

  • infiniflow/ragflow#15366: Related edits to /documents/<doc_id>/preview with a different guardrail (empty-storage blob handling).
  • infiniflow/ragflow#14625: Similar authorization gating added for document download routes using DocumentService.accessible.

Suggested reviewers

  • wangq8

🐰 I hopped along the API trail,
Restored the gate that once went pale,
No peeks beyond the tenant line,
Access checked, the bytes confined,
Hooray — the preview's now benign!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(api): restore accessible check on document preview' clearly and concisely summarizes the main change: restoring a removed authorization check on a document preview endpoint.
Description check ✅ Passed The description fully addresses the required template sections: it explains the problem (missing authorization check after PR #15146), includes the bug fix checkbox marked, and provides comprehensive context about the security issue.
Linked Issues check ✅ Passed The PR successfully addresses all objectives from issue #15501: restores DocumentService.accessible check, denies access for non-authorized users, returns generic 'Document not found!' response, and leaves SDK routes unchanged.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to restoring the missing authorization check in the document preview handler; no unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@kiannidev

Copy link
Copy Markdown
Contributor Author

Hi, @wangq8 , @Haruko386 , @JinHai-CN @yingfeng @xugangqiang
Please review this PR

@xugangqiang

Copy link
Copy Markdown
Contributor

@buua436 please help to review.

@xugangqiang
xugangqiang requested a review from buua436 June 3, 2026 03:17

@buua436 buua436 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fix may affect the preview behavior of embedded chat.

@kiannidev

Copy link
Copy Markdown
Contributor Author

@buua436 Thanks — understood.

This restores the pre-#15146 accessible check only; embed preview still uses /documents/{id}/preview with the same auth token as embed chat, so owner-token embeds should be unchanged. It mainly blocks cross-tenant preview by doc UUID.

If you have a failing setup, please share repro steps.

Thanks again

kiannidev added 2 commits June 3, 2026 15:20
Resolve document_api import conflict: keep accessible check and
AUTH_BETA embed auth from main.
@kiannidev
kiannidev force-pushed the fix/15501-preview-accessible branch from 9c8a414 to dee365b Compare June 3, 2026 13:26
@kiannidev
kiannidev requested a review from buua436 June 3, 2026 13:27
@wangq8
wangq8 merged commit d26d799 into infiniflow:main Jun 4, 2026
1 check passed
Lobster-0429 added a commit to Lobster-0429/ragflow that referenced this pull request Jun 4, 2026
The /documents/<doc_id>/preview handler gained a duplicate
DocumentService.accessible() check (infiniflow#15505) placed before get_by_id, on
top of the canonical post-existence check (infiniflow#15508). The early call makes
the handler probe access for a missing doc, which the infiniflow#15501 regression
test forbids and which leaks a server_error instead of 'Document not
found!'. Remove the redundant check (line 1928 still enforces access, so
cross-tenant reads stay blocked).

Also extend the test's api.apps stub with AUTH_JWT/AUTH_API/AUTH_BETA and a
factory-aware login_required so loading document_api.py (which now imports
those constants via infiniflow#15581) does not fail at import time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: REST document preview dropped DocumentService.accessible check

4 participants