Fix path join#2138
Open
alastair wants to merge 7 commits into
Open
Conversation
str.replace could potentially replace text that occurs in the middle of the string. This can probably not happen in this specific case, but relpath is more correct
** implies that we want to do a recursive lookup, but we only have one level of subdirs in this directory
End result is the same but it shows intent a bit better
`validate_input_csv_file` joined the user-supplied `audio_filename` field directly with `sounds_base_dir` and only checked the resulting path's extension and existence. A CSV row with `audio_filename` like `../789/something.wav` resolved outside the submitting user's upload directory, which then fed `bulk_describe_from_csv` and allowed copying the resolved file into the attacker's account. Resolve the candidate path with `os.path.realpath` and require it to share a common ancestor with the (resolved) `sounds_base_dir` before accepting it. Downstream code consumes the validated, dedup-filtered set, so this single guard is sufficient. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Covers both relative-escape (`../somewhere/file.wav`) and absolute-path (`/etc/passwd.wav`) variants for the validation added in the previous commit. The CSV row goes through the normal validator and both rows end up with `audio_filename` in `line_errors`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Issue(s)
Inspired by #2135
Description
We had a number of places in the codebase where we use string concatenation to construct paths on disk. This has a few issues
Here we replace all uses of string concatenation/truncating with methods from os.path. Additional fix the one case we found where a user provided path is unsafely concatenated (would have been a problem with os.path.join too)
Deployment steps:
After this is deployed we can remove the trailing
/from all location settings