Skip to content

Security: fix path traversal and arbitrary filesystem access vectors; cross-platform test fixes#2

Merged
lmangani merged 5 commits intomainfrom
copilot/add-api-documentation-and-models-switch
Mar 21, 2026
Merged

Security: fix path traversal and arbitrary filesystem access vectors; cross-platform test fixes#2
lmangani merged 5 commits intomainfrom
copilot/add-api-documentation-and-models-switch

Conversation

Copy link
Contributor

Copilot AI commented Mar 21, 2026

User-controlled input could reach the filesystem outside intended boundaries via three distinct vectors. Additionally, hardcoded Unix paths in security tests caused Windows CI failures.

Security fixes

Path traversal in GET /v1/audio

The old sanitization (replace(/\.\./g, "")) is bypassable. Replaced with resolve() + isPathWithin() containment check — any path resolving outside audioStorageDir returns 404.

- const safePath = parsePath(pathParam).replace(/\.\./g, "").replace(/^\/+/, "");
- const filePath = join(config.audioStorageDir, safePath);
+ const requestedPath = parsePath(pathParam).replace(/^\/+/, "");
+ const filePath = resolve(join(config.audioStorageDir, requestedPath));
+ if (!isPathWithin(filePath, config.audioStorageDir)) return detailRes("Not Found", 404);

Arbitrary path access via src_audio_path / reference_audio_path

JSON bodies could supply {"src_audio_path": "/etc/shadow"} and have it forwarded directly to ace-synth --src-audio. Now validated to be within tmpDir (multipart upload landing zone) or audioStorageDir before the binary is invoked.

Arbitrary path access via per-request lm_model_path

Same class of issue — JSON bodies could override the LM model path to any file passed to ace-lm --lm. When ACESTEP_MODELS_DIR is configured, the resolved path must be within that directory.

Shared utility — src/paths.ts

Added isPathWithin(child, parent): resolves both sides with path.resolve(), then checks for exact equality or a sep-terminated prefix. The sep guard prevents /storage/audiovil from matching /storage/audio.

Cross-platform test fixes — test/security.test.ts

Hardcoded Unix paths like "/storage/audio/abc123.mp3" broke Windows CI. Fixed by:

  • Deriving storageDir via resolve("/storage/audio") (picks up drive letter on Windows)
  • Using join(storageDir, ...) for .toBe() expectations
  • Using storageDir + sep for .startsWith() checks

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Add full API documentation with supported endpoints Add full API docs and make model listing dynamic from ACESTEP_MODEL_MAP Mar 21, 2026
Copilot AI requested a review from lmangani March 21, 2026 10:10
Copilot AI changed the title Add full API docs and make model listing dynamic from ACESTEP_MODEL_MAP Auto-discover GGUF models from disk; ACESTEP_MODELS as filter gate Mar 21, 2026
Copilot AI changed the title Auto-discover GGUF models from disk; ACESTEP_MODELS as filter gate Security: path traversal + arbitrary filesystem access hardening Mar 21, 2026
…nstead of hardcoded Unix paths

Co-authored-by: lmangani <1423657+lmangani@users.noreply.github.com>
Agent-Logs-Url: https://github.com/audiohacking/acestep-cpp-api/sessions/051c1563-8de6-4e16-bb20-5bbd9243032a
Copilot AI changed the title Security: path traversal + arbitrary filesystem access hardening Security: fix path traversal and arbitrary filesystem access vectors; cross-platform test fixes Mar 21, 2026
@lmangani lmangani marked this pull request as ready for review March 21, 2026 11:07
@lmangani lmangani merged commit b25fd65 into main Mar 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants