-
Notifications
You must be signed in to change notification settings - Fork 566
fix: API 400 - absolute audio file paths are not allowed for temp folder #447
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
Conversation
This PR resolves the 400 Bad Request error triggered during file uploads (e.g., "Analyseer DNA") where the server incorrectly rejected absolute paths for its own temporary files.
Key Changes:
Fix: Updated _validate_audio_path to allow absolute paths strictly when they reside within the system's temporary directory.
Hardening: Replaced string-based prefix checks with os.commonpath to prevent directory boundary bypasses (e.g., /tmp_evil vs /tmp).
Refactor: Moved path validation to the API entry points (JSON/Multipart handlers) to distinguish between untrusted user-provided strings and trusted server-generated paths, ensuring _build_request no longer trips over internal temp files.
📝 WalkthroughWalkthroughThe API server's audio path validation has been tightened to restrict absolute paths to the system temporary directory only, while consolidating validation across JSON and form-based input handlers. Path normalization and boundary checks now apply consistently throughout request construction to prevent directory traversal. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
There was a problem hiding this 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
🤖 Fix all issues with AI agents
In `@acestep/api_server.py`:
- Around line 905-921: The current temp-path acceptance logic in the code around
the path resolution (use of system_temp and requested_path and is_in_temp)
accepts any path under the system temp dir and thereby allows user-supplied
absolute paths; change it to only accept temp paths that the server actually
created for the current request/session by maintaining and checking a
per-request/per-session whitelist (e.g., store filenames/paths returned by
tempfile.mkstemp() when creating files and validate requested_path against that
whitelist) and reject any absolute temp paths not present in that whitelist;
also remove the redundant local import of tempfile (it’s already imported at
module level) and keep the os.path.commonpath check only as a secondary guard
after whitelist validation.
|
|
||
| # Resolve requested path and system temp path to normalized absolute forms | ||
| import tempfile | ||
| system_temp = os.path.realpath(tempfile.gettempdir()) | ||
| requested_path = os.path.realpath(path) | ||
|
|
||
| # SECURE CHECK: Use os.path.commonpath to verify directory boundary integrity. | ||
| # This prevents prefix bypasses (e.g., /tmp_evil when /tmp is allowed). | ||
| try: | ||
| is_in_temp = os.path.commonpath([system_temp, requested_path]) == system_temp | ||
| except ValueError: | ||
| # Occurs on Windows if paths are on different drives | ||
| is_in_temp = False | ||
|
|
||
| if is_in_temp: | ||
| # Accept server-generated files in temp | ||
| return requested_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# Check module-level imports and the import at line 907
head -50 acestep/api_server.py | grep -n "import"Repository: ace-step/ACE-Step-1.5
Length of output: 1025
🏁 Script executed:
# Check around line 26 for tempfile import and line 907
sed -n '20,30p' acestep/api_server.py
sed -n '900,925p' acestep/api_server.pyRepository: ace-step/ACE-Step-1.5
Length of output: 1322
🏁 Script executed:
# Search for how temp files are created and named in the codebase
rg -n "mkstemp|mkdtemp|NamedTemporaryFile|tempfile\." --type py -B2 -A2Repository: ace-step/ACE-Step-1.5
Length of output: 2437
Security concern: User-controlled absolute paths in temp directory bypass per-session validation.
The updated logic now accepts any absolute path within the system temp directory, including paths that users supply directly. While tempfile.mkstemp() generates cryptographically random file names (making enumeration impractical), the function does not verify that a user-provided path actually corresponds to a legitimate server-generated file for the current request/session. This allows potential cross-request file access if an attacker successfully predicts or enumerates temp file names.
Recommended mitigations:
- Maintain a whitelist of temp files created for the current request/session and validate against it before accepting user-provided temp paths
- Only accept absolute temp paths that were generated by the server, not user-supplied strings
- Document the security boundary clearly if accepting all temp paths is intentional
Additionally, remove the redundant import tempfile at line 907 (tempfile is already imported at module level on line 26).
🔧 Proposed fix for redundant import
if not path:
return None
-
- # Resolve requested path and system temp path to normalized absolute forms
- import tempfile
+
+ # Resolve requested path and system temp path to normalized absolute forms
system_temp = os.path.realpath(tempfile.gettempdir())🤖 Prompt for AI Agents
In `@acestep/api_server.py` around lines 905 - 921, The current temp-path
acceptance logic in the code around the path resolution (use of system_temp and
requested_path and is_in_temp) accepts any path under the system temp dir and
thereby allows user-supplied absolute paths; change it to only accept temp paths
that the server actually created for the current request/session by maintaining
and checking a per-request/per-session whitelist (e.g., store filenames/paths
returned by tempfile.mkstemp() when creating files and validate requested_path
against that whitelist) and reject any absolute temp paths not present in that
whitelist; also remove the redundant local import of tempfile (it’s already
imported at module level) and keep the os.path.commonpath check only as a
secondary guard after whitelist validation.
This PR resolves the 400 Bad Request error triggered during file uploads where the server incorrectly rejected absolute paths for its own temporary files.
Key Changes:
Summary by CodeRabbit
Release Notes