feat(apps): support absolute paths for +file-upload --file#1978
feat(apps): support absolute paths for +file-upload --file#1978chenxingyang1019 wants to merge 2 commits into
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesFile upload path handling
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
shortcuts/apps/apps_file_upload.goshortcuts/apps/apps_file_upload_test.go
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@674a8dd72c8e0084d1af62c2e4a15462dc2cfa50🧩 Skill updatenpx skills add larksuite/cli#feat/apps-file-upload-abs-path -y -g |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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.
What
apps:+file-uploadnow accepts absolute paths (and paths outside thecurrent working directory) for
--file.Previously
--filewas read through the sandboxedrctx.FileIO(), whoseSafeInputPathjail rejects any non-relative / out-of-tree path(
must be a relative path within the current directory). This command nowreads the local file via
osdirectly.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
identical (
osresolves the same path against the same CWD).--filerequired, directory rejection, and the 100 MB size cap are all preserved.
+file-uploadis changed;the shared
SafeInputPathjail and every other--file/--outputconsumer (e.g.
db-data-import --file,db-data-export --output) areuntouched. The two
oscalls carry//nolint:forbidigowith a rationale,matching the existing precedent in
apps_env_pull.go. The source file isonly read locally and streamed to the app's storage.
Testing
TestAppsFileUpload_AcceptsAbsolutePath(absolute,out-of-tree path) + existing relative/validation tests all pass.
relative-path upload unchanged.
Summary by CodeRabbit