Repository navigation
fix(web): stop CodeQL reopening the thumbnail path alert by using checks it recognises - #638
Conversation
CodeQL's py/path-injection query does not model Path.resolve() and Path.is_relative_to(), so it kept reopening the same finding in ensure_thumbnail each time the lines moved. The checks now use os.path.realpath and str.startswith against the root plus a trailing separator, which the query treats as a normalisation and a guard. Accept and reject behaviour is unchanged, including the root itself and a sibling directory that shares the root's name as a prefix; new tests pin both cache layouts and the legacy folder fallback.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 2 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
🐳 Dev images published!
The dev/test instance will pick up these changes automatically (Portainer GitOps). To test locally: docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #638 +/- ##
==========================================
+ Coverage 94.90% 94.94% +0.04%
==========================================
Files 89 89
Lines 22703 22705 +2
==========================================
+ Hits 21546 21558 +12
+ Misses 1157 1147 -10
🚀 New features to boost your workflow:
|
|
CodeQL evidence for this change. The PR's own analysis reports 0 Python results, but it is diff-informed: it only reports results in changed lines. Line 303 ( So I also ran the same query (CodeQL 2.27.5,
|
…l checks Three of the new containment guards had no test that fails on Linux: resolving the media root, resolving the thumbs root, and the trailing separator on the legacy fallback path. A media root or cache dir given as a symlink must still serve, and an alternate folder that resolves to the media root itself still passes, as Path.is_relative_to did. Both tests pass on main and on this branch.
|
🐳 Dev images published!
The dev/test instance will pick up these changes automatically (Portainer GitOps). To test locally: docker pull drumsergio/telegram-archive:dev
docker pull drumsergio/telegram-archive-viewer:dev |
CodeQL keeps reporting a path injection in
ensure_thumbnail(alert #71, and #25, #26, #36, #54, #64 to #67 before it). The code already resolves each path and checks that it stays inside its root. But CodeQL does not modelPath.resolve()orPath.is_relative_to(), so it does not see that check. Each time the lines move, the dismissed alert comes back under a new number.The tainted input is the
sizepath parameter. It goes into the thumbnail destination path.Fix
The three checks (the source file, the legacy-folder fallback and the thumbnail destination in both cache layouts) now use
os.path.realpathand thenstr.startswith, inline. CodeQL's query treats these as a normalisation and a guard.The behaviour does not change:
..are resolved as before.Path.resolve()callsos.path.realpathitself.is_relative_to, and a sibling such asmedia-evilnext tomediadoes not.Tests
New tests in
tests/test_web_thumbnails.pycover both cache layouts and the legacy fallback:..in the folder and in the file name, absolute paths, symlinks inside the media root that point outside, a sibling directory with the root's name as a prefix, and the root itself. They pass onmainand on this branch. Mutants that drop the trailing separator or the fallback check make them fail.