Skip to content

feat(apps): support absolute paths for +file-upload --file#1978

Closed
chenxingyang1019 wants to merge 2 commits into
mainfrom
feat/apps-file-upload-abs-path
Closed

feat(apps): support absolute paths for +file-upload --file#1978
chenxingyang1019 wants to merge 2 commits into
mainfrom
feat/apps-file-upload-abs-path

Conversation

@chenxingyang1019

@chenxingyang1019 chenxingyang1019 commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

What

apps:+file-upload now accepts absolute paths (and paths outside the
current working directory) for --file.

Previously --file was read through the sandboxed rctx.FileIO(), whose
SafeInputPath jail rejects any non-relative / out-of-tree path
(must be a relative path within the current directory). This command now
reads the local file via os directly.

Why

Operators / agents frequently want to upload a file that isn't under the
process CWD (e.g. an absolute path produced by another tool). The jail
forced an awkward cd + relative-path dance.

Scope & safety

  • Additive, no regression. For a relative path inside CWD the result is
    identical (os resolves the same path against the same CWD). --file
    required, directory rejection, and the 100 MB size cap are all preserved.
  • Deliberate, scoped sandbox exception. Only +file-upload is changed;
    the shared SafeInputPath jail and every other --file/--output
    consumer (e.g. db-data-import --file, db-data-export --output) are
    untouched. The two os calls carry //nolint:forbidigo with a rationale,
    matching the existing precedent in apps_env_pull.go. The source file is
    only read locally and streamed to the app's storage.

Testing

  • New unit test TestAppsFileUpload_AcceptsAbsolutePath (absolute,
    out-of-tree path) + existing relative/validation tests all pass.
  • Verified end-to-end against production: absolute-path upload succeeds,
    relative-path upload unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • File uploads now support absolute paths and files located outside the current working directory.
    • Existing validation remains in place, including required file checks, directory rejection, and the 100 MB size limit.
  • Tests
    • Added coverage confirming successful uploads from absolute file paths.

file-upload now reads the local --file via os directly instead of the
sandboxed rctx.FileIO(), so absolute paths — and paths outside the
current working directory — are accepted. Previously the shared
SafeInputPath jail rejected any non-relative / out-of-tree path.

Relative-path behavior is unchanged (os resolves the same path against
the same cwd); --file required, directory rejection, and the 100 MB cap
are all preserved. The two os calls carry //nolint:forbidigo with a
rationale, matching the existing precedent in apps_env_pull.go.

Adds a unit test covering an absolute, out-of-tree upload path.
@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Jul 21, 2026
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c25b36a5-ec51-4c8d-bcb6-0464b18b2ced

📥 Commits

Reviewing files that changed from the base of the PR and between 8c4a5fa and 674a8dd.

📒 Files selected for processing (1)
  • shortcuts/apps/apps_file_upload.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • shortcuts/apps/apps_file_upload.go

📝 Walkthrough

Walkthrough

apps file-upload now uses direct local filesystem calls for validation and reading, allowing absolute and out-of-tree paths while retaining the existing upload workflow. A new test verifies absolute-path uploads and request-body contents.

Changes

File upload path handling

Layer / File(s) Summary
Direct filesystem validation and access
shortcuts/apps/apps_file_upload.go
The command documents and uses os.Stat and os.ReadFile instead of sandboxed file I/O, while preserving existing validation and upload processing.
Absolute-path upload coverage
shortcuts/apps/apps_file_upload_test.go
Adds an end-to-end test confirming an absolute file path is accepted and uploaded with matching contents.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: absolute-path support for +file-upload --file.
Description check ✅ Passed The description covers motivation, scope, safety, and testing, but it doesn't follow the repository's exact section template or include Related Issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/apps-file-upload-abs-path

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@shortcuts/apps/apps_file_upload.go`:
- Around line 60-64: Reinstate sandboxed file access in the file-upload flow:
use rctx.FileIO().Stat(f) and rctx.FileIO() with cmdutil.ReadInputFile for
content reads, and remove the direct-os justification and unused os import in
shortcuts/apps/apps_file_upload.go (lines 13, 30-35, 60-64, and 89-92). Remove
or rewrite the absolute/out-of-tree path test in
shortcuts/apps/apps_file_upload_test.go (lines 152-198) to expect SafeInputPath
sandbox enforcement.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4fdcca43-6d75-4bbd-8155-3458d32901c4

📥 Commits

Reviewing files that changed from the base of the PR and between ad4a6d6 and 8c4a5fa.

📒 Files selected for processing (2)
  • shortcuts/apps/apps_file_upload.go
  • shortcuts/apps/apps_file_upload_test.go

Comment thread shortcuts/apps/apps_file_upload.go
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@674a8dd72c8e0084d1af62c2e4a15462dc2cfa50

🧩 Skill update

npx skills add larksuite/cli#feat/apps-file-upload-abs-path -y -g

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.99%. Comparing base (fb57e17) to head (674a8dd).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1978      +/-   ##
==========================================
- Coverage   75.00%   74.99%   -0.01%     
==========================================
  Files         898      900       +2     
  Lines       94912    95120     +208     
==========================================
+ Hits        71184    71338     +154     
- Misses      18269    18302      +33     
- Partials     5459     5480      +21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Expand the security NOTE: the accepted risk is bounded because the upload
destination is controlled, not attacker-chosen. The miaoda apps flow reads
the local file and uploads it to a presigned upload_url from miaoda's own
file_pre_upload endpoint (a miaoda-owned domain, into the caller's own app
storage under their own token). Widening --file only changes what can be
read locally, not where it can be sent, so it is not an exfiltration
primitive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant