Skip to content

Improve randomness of uploaded file names and files created by tempnam() #14364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

arnaud-lb
Copy link
Member

@arnaud-lb arnaud-lb commented May 29, 2024

Uploaded files are created with a name in the form /tmp/phpXXXXXX, where XXXXXX is given one of 62^6 different values by mkstemp(3). According to this blogpost, it is possible to guess this name by brute forcing, with a reasonable number of attempts. This can be used to exploit a vulnerable applications.

Here I add 64 bits of additional randomness before the XXXXXX pattern, to make this attack unpractical.

The change also applies to tempnam() and to platforms without mkstemp().

@arnaud-lb arnaud-lb changed the title Improve randomness of uploaded file names and files created by tempnam() [wip] Improve randomness of uploaded file names and files created by tempnam() May 29, 2024
@arnaud-lb arnaud-lb changed the title [wip] Improve randomness of uploaded file names and files created by tempnam() Improve randomness of uploaded file names and files created by tempnam() May 30, 2024
@arnaud-lb arnaud-lb marked this pull request as ready for review May 30, 2024 15:47
@arnaud-lb arnaud-lb requested a review from bukka as a code owner May 30, 2024 15:47
Copy link
Member

@TimWolla TimWolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way the randomness is used and processed LGTM.

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arnaud-lb arnaud-lb closed this in b4325d6 Jun 10, 2024
@arnaud-lb
Copy link
Member Author

Thank you @bukka @nielsdos @TimWolla!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants