Fix path traversal vulnerability in the pfp feature #25
+278
−142
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.
Read about the exploit here (I know I'm publishing this before the PR is actually accepted, but there's a very small window of opportunity): https://mataiodoxion.github.io/blog/smashing-morts-server-1/
TL;DR Most notably, I could have escalated my permissions on the site to admin by exfiltrating
.envsecrets, logging into the admin server, and making some queries. I did, however, escalate my privileges with the RCE (through the code runner) a bit earlier.Updated two files to use a safer version of
os.path.join()withsecure_filename()at both the fetch level and interalsetterlevel. Main idea is that 1) inputs weren't properly sanitized and 2)os.path.join()will take an absolute path over a local path, meaning I could set that to any file I wanted on the Docker image (including.env, of course).PS: My IDE's built in linter automatically formatted a bunch of the code, so some of the code format styling changed a bit.
Notable lines:
model/pfp.py: linter didn't mess with the additions too much heremodel/user.py: 348-364