fix(api): reject path traversal in external subtitle filename - #1385
Merged
revam merged 4 commits intoJul 27, 2026
Conversation
Foowy
marked this pull request as draft
July 13, 2026 16:20
Foowy
marked this pull request as ready for review
July 13, 2026 16:22
Contributor
Author
|
Purely security check, most users will not see this, but we might as well not be a weak point |
revam
requested changes
Jul 16, 2026
Foowy
marked this pull request as draft
July 16, 2026 19:40
Foowy
force-pushed
the
security/file-controller-hardening
branch
from
July 18, 2026 16:36
d72f683 to
c58aaa6
Compare
Contributor
Author
|
Used a 250ms match timeout for |
Foowy
marked this pull request as ready for review
July 18, 2026 18:58
…s-control bypass `GetExternalSubtitle` passed the raw `filename` route parameter into `Path.Combine` with no traversal or absolute-path check, allowing an authenticated (or anonymous, if `AllowAnonymousFileStreamingInAPIv3` is enabled) caller to read arbitrary files on the host via `../` sequences or a rooted path. Reject any `filename` containing `/`, `\`, or equal to `.`/`..` before combining paths. `GetFileStreamInternal`, `GetFileStreamDirectory`, and `GetExternalSubtitle` also had no `AllowedSeries` check, unlike other endpoints in this controller — a restricted/parental-control user account could stream video or subtitles for series outside their allowed list. Added `IsSeriesAllowedForFile`, reusing the existing `JMMUser.AllowedSeries` check.
…versal fix only Scoped this PR down to the path-traversal fix in GetExternalSubtitle. The AllowedSeries check only matters for installs using Shoko's restricted/parental-control user profiles and isn't worth bundling with the traversal fix.
…tles The previous check rejected any `filename` containing `/` or `\`, which also blocked legitimate subtitles living in a subfolder next to the video, while doing nothing to stop encoded traversal segments embedded elsewhere in the name. Replaced with a regex that rejects `.` /`..` path segments specifically (`PathTraversalPattern`), and added a whitelist check against the video's known external subtitle filenames (`MediaInfo.TextStreams`) so `filename` can only resolve to a subtitle actually linked to the file.
SonarCloud flagged the unbounded Regex constructor as a ReDoS risk. 250ms matches the timeout convention already used by LogService's filter regex.
Foowy
force-pushed
the
security/file-controller-hardening
branch
from
July 27, 2026 02:43
8ddbec9 to
1f7d993
Compare
|
revam
approved these changes
Jul 27, 2026
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
GetExternalSubtitle(FileController) passed the rawfilenameroute parameter straight intoPath.Combinewith no traversal/absolute-path check — an authenticated caller (or anonymous, ifAllowAnonymousFileStreamingInAPIv3is on) could read arbitrary files on the host via../sequences or a rooted path.filenamecontaining/or\— but that also blocked legitimate subtitles living in a subfolder next to the video, while doing nothing to stop encoded traversal segments embedded elsewhere in the name. Replaced with a regex (PathTraversalPattern) that specifically rejects./..path segments, plus a whitelist check against the video's actual known external subtitle filenames (MediaInfo.TextStreams) —filenamecan now only ever resolve to a subtitle genuinely linked to that file, not just any traversal-free string.LogService's filter regex.AllowedSeries(restricted/parental-control profile) check to the file-streaming endpoints, since they were missing it unlike other endpoints in this controller — that was dropped to keep this PR scoped to the traversal fix only; it's a separate, lower-severity gap that can be addressed independently.Found during a local security review of the file-streaming surface.
Test plan
dotnet build Shoko.Server.sln -c Release— 0 errorsRebase history
master@a9126a417(4 commits), now at1f7d99355