Skip to content

cookies.txt is created world-readable - #511

Merged
xroche merged 3 commits into
masterfrom
codeql-world-writable
Jul 10, 2026
Merged

cookies.txt is created world-readable#511
xroche merged 3 commits into
masterfrom
codeql-world-writable

Conversation

@xroche

@xroche xroche commented Jul 9, 2026

Copy link
Copy Markdown
Owner

CodeQL's cpp/world-writable-file-creation flags every file-creating fopen: 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 is cookie_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_cookies selftest asserts both modes (proven by reverting each fix). The rule is excluded via a query filter so it stops tripping PR gates one new fopen at a time; the open baseline alerts get dismissed once this lands.

Comment thread src/htsselftest.c Fixed
xroche and others added 2 commits July 9, 2026 20:16
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
xroche force-pushed the codeql-world-writable branch from 87fd83d to a4b05a3 Compare July 9, 2026 18:16
Comment thread src/htsselftest.c Fixed
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>
@xroche
xroche merged commit 9c01812 into master Jul 10, 2026
18 checks passed
@xroche
xroche deleted the codeql-world-writable branch July 27, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants