Skip to content

Do not create world readable temp files for response content - #1205

Merged
rbri merged 3 commits into
HtmlUnit:masterfrom
Vidya-m78:response-temp-file-permissions
Nov 23, 2026
Merged

rbri merged 3 commits into
HtmlUnit:masterfrom
Vidya-m78:response-temp-file-permissions

Conversation

@Vidya-m78

Copy link
Copy Markdown
Contributor

HttpWebConnection.downloadContent() stores a response that exceeds WebClientOptions.getMaxInMemory() (500 KiB by default) in the temp directory, and File.createTempFile() creates that file with the permissions of the umask, rw-r--r-- on Posix systems, so every other user of the machine can read the cached page, download or API response for as long as the WebResponse is alive. DebuggingWebConnection has the same exposure for its report folder in the temp directory, which also holds the POST parameters of the recorded requests. Files.createTempFile() restricts a new file to the owner; without the change the two new tests fail with 'expected: but was: ' and 'expected: but was: '.

@rbri

rbri commented Nov 21, 2026

Copy link
Copy Markdown
Member

@Vidya-m78 what do you think about moving the createReportFolder() functionality to FileUtils - having a helper here that createsUser only folders?

@rbri
rbri force-pushed the master branch 4 times, most recently from 93e8d89 to 893439d Compare November 22, 2026 10:29
@Vidya-m78

Copy link
Copy Markdown
Contributor Author

Makes sense, that's the better home for it. Moved it to org.htmlunit.util.FileUtils as createUserOnlyDirectories(Path), so DebuggingWebConnection just calls the helper now (fully qualified there because the class already imports the commons-io FileUtils). Also covered it in FileUtilsTest, including the parent directories.

The temp file side stays as is, Files.createTempFile() already restricts the file to the owner, so there is nothing to wrap there.

@rbri
rbri merged commit 6ec4eb5 into HtmlUnit:master Nov 23, 2026
5 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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