Repository navigation
fix(handler): restrict file downloads to tasks directory — prevent API key leakage - #297
Merged
wulien merged 1 commit intoJun 25, 2026
Conversation
DownloadFile used filepath.Join(".", requestedFile) with no boundary
check, allowing any client to read arbitrary files from the server's
working directory — including config/config.toml which contains all
configured API keys (OpenAI, Aliyun, etc.).
Fix: resolve both the tasks directory and the requested path to
absolute paths, then reject requests whose resolved path does not
start with the tasks directory prefix.
Fixes krillinai#296
Signed-off-by: kapil971390 <kapil69265@gmail.com>
wulien
added a commit
that referenced
this pull request
Oct 14, 2026
…rsal fix(handler): restrict file downloads to tasks directory — prevent API key leakage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
DownloadFilehandler ininternal/handler/subtitle_task.goaccepts arbitrary file paths via the*filepathroute parameter and serves them with no directory restriction.Root cause:
filepath.Join(".", requestedFile)resolves absolute paths by design —filepath.Join(".", "/config/config.toml")returns"config/config.toml", not an error. Any caller can read any file the process can read.Impact: The
config/config.tomlfile typically contains API keys for OpenAI, Anthropic, Deepseek, ElevenLabs, and similar services. A single GET request leaks all of them:Fix: Resolve both the requested path and the
tasks/output directory to absolute paths, then reject requests that don't start with the tasks directory prefix (HTTP 403).This was found during a security-focused review of the file download endpoint.
Test plan
GET /api/file/tasks/<valid-output-file>→ 200, file servedGET /api/file/config/config.toml→ 403 ForbiddenGET /api/file/../config/config.toml→ 403 ForbiddenGET /api/file//etc/passwd→ 403 Forbidden