Skip to content

fix(security): tenant-scope FilePreviewApi text-extract endpoint (GHSA-2qwc-c2cc-2xwv)#35797

Merged
laipz8200 merged 5 commits into
langgenius:mainfrom
xr843:fix/ghsa-2qwc-file-preview-tenant-check
May 14, 2026
Merged

fix(security): tenant-scope FilePreviewApi text-extract endpoint (GHSA-2qwc-c2cc-2xwv)#35797
laipz8200 merged 5 commits into
langgenius:mainfrom
xr843:fix/ghsa-2qwc-file-preview-tenant-check

Conversation

@xr843
Copy link
Copy Markdown
Contributor

@xr843 xr843 commented May 5, 2026

Summary

api/controllers/console/files.py FilePreviewApi.get (the console-authenticated /files/<file_id>/preview text-extract endpoint) only checked authentication; the underlying FileService.get_file_preview(file_id) looked the file up by id alone, with no tenant filter. An authenticated user from tenant A could read the extracted-text preview of any UploadFile whose UUID they could obtain (or guess), including files belonging to other tenants.

Fix

Two surgical changes:

  1. Service layerFileService.get_file_preview now takes tenant_id and adds UploadFile.tenant_id == tenant_id to the lookup query.
  2. ControllerFilePreviewApi.get resolves the caller's tenant via current_account_with_tenant() and passes it through.

5 existing test sites (3 integration, 2 unit) updated for the new signature.

Scope of audit

I greppped for other callers of get_file_preview. Only the console controller and the 5 test sites — no other production callers to update.

The HMAC-signed file endpoints (api/controllers/files/image_preview.py ImagePreviewApi / FilePreviewApi) are a different code path: they verify a per-file HMAC signature instead of relying on session auth, so cross-tenant access there requires already possessing a valid signature for the target file. Not affected by this advisory; not changed in this PR.

Refs

Credit / authorship

This PR applies Ido Shani's original patch verbatim (git am). Both commits authored by him. PR opened by me on his behalf since he didn't have permission to add me to the GHSA — see #35699. Marking as draft until reporter / a maintainer signs off.

zafido added 2 commits May 5, 2026 17:51
Signed-off-by: xr843 <137012659+xr843@users.noreply.github.com>
Signed-off-by: xr843 <137012659+xr843@users.noreply.github.com>
@xr843 xr843 mentioned this pull request May 5, 2026
6 tasks
@xr843 xr843 marked this pull request as ready for review May 6, 2026 04:19
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 6, 2026
The tenant-scoping fix calls current_account_with_tenant() in
FilePreviewApi.get, which hits flask-login and trips on a Flask app
without login_manager configured. Reuse the existing
mock_account_context fixture to short-circuit it.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 0.00% 43.70% +43.70%
Strict coverage 0.00% 43.23% +43.23%
Typed symbols 0 22,071 +22,071
Untyped symbols 0 28,746 +28,746
Modules 0 2553 +2,553

Copy link
Copy Markdown
Member

@laipz8200 laipz8200 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 14, 2026
@laipz8200 laipz8200 added this pull request to the merge queue May 14, 2026
Merged via the queue into langgenius:main with commit 432a641 May 14, 2026
27 checks passed
zhangtaodemama added a commit to zhangtaodemama/langgenius-dify-bfaadcb0c706 that referenced this pull request May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants