cookies.txt is created world-readable - #511
Merged
Merged
Conversation
cookie_save() wrote the jar with fopen, so live session cookies ended up world-readable under the usual umask. Create it O_CREAT 0600 on Unix (new HTS_PROTECT_FILE), fchmod pre-existing jars down to 0600 on rewrite, and close the fd if fdopen fails. The st_cookies selftest asserts both the fresh-create and the tighten-on-rewrite mode (ASan-independent, proven by reverting each fix). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
The rule flags every file-creating fopen (0666 & ~umask): 53 baseline alerts over mirror/cache/log/test output where umask-controlled modes are the intended, conventional behavior. Its one real catch, the cookies jar, is now kept 0600 explicitly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.com>
xroche
force-pushed
the
codeql-world-writable
branch
from
July 9, 2026 18:16
87fd83d to
a4b05a3
Compare
The mode assertions alone would pass a cookie_save that creates an empty 0600 file and returns 0; check st_size on both saves (proven by a negative control that skips the write loop). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Xavier Roche <roche@httrack.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.
CodeQL's
cpp/world-writable-file-creationflags every file-creatingfopen: 53 baseline alerts across mirror output, cache, logs, and test fixtures, where umask-controlled permissions are standard Unix tool behavior (wget and cp do the same). The one place it had a point iscookie_save(): cookies.txt holds live session cookies and was left world-readable.The jar is now created 0600 on Unix, a pre-existing world-readable jar is tightened to 0600 on the next save, and the
st_cookiesselftest asserts both modes (proven by reverting each fix). The rule is excluded via a query filter so it stops tripping PR gates one newfopenat a time; the open baseline alerts get dismissed once this lands.