Skip to content
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

File System Security Issue in Custom Auth Article #5846

Closed
wants to merge 2 commits into from
Closed

File System Security Issue in Custom Auth Article #5846

wants to merge 2 commits into from

Conversation

mattjanssen
Copy link
Contributor

Q A
Doc fix? yes
New docs? no
Applies to all
Fixed tickets #5845

I hope to address this security concern: If $token->nonce is set to [ANY USER INPUT] and later we run file_put_contents($token->nonce, time()) are we allowing hackers to destroy any www-writable file in the system?

I did notice that $nonce is run through base64_decode($nonce) later in the article, implying nonce needs to be a Base64 string. Could this Regex be updated to only accept a Base64 string [a-zA-Z+/]+={0,2} for the nonce?

At the same time, Base64 allows / characters, so file_put_contents() would fail in those cases, so even this change, while secure, seems flawed. Replace [+/] with [-_]?

I hope to address this security concern: If `$token->nonce` is set to [ANY USER INPUT] and later we run `file_put_contents($token->nonce, time())` are we allowing hackers to destroy any www-writable file in the system?

I did notice that `$nonce` is run through `base64_decode($nonce)` later in the article, implying nonce needs to be a Base64 string. Could this Regex be updated to only accept a Base64 string `[a-zA-Z+/]+={0,2}` for the nonce?

At the same time, Base64 allows `/` characters, so `file_put_contents()` would fail in those cases, so even this change, while secure, seems flawed. Replace [+/] with [-_]?
@xabbuh
Copy link
Member

xabbuh commented Oct 28, 2015

What about not using the nonce itself as the filename but passing it to a hash function or normalise it another way first?

@timglabisch
Copy link
Contributor

👍 using a hash function

@mattjanssen
Copy link
Contributor Author

md5($nonce)?

And force Base64 string in regex or not? We still have a base64_decode($nonce) in there.

@bshaffer
Copy link
Contributor

👍 good catch

@wouterj
Copy link
Member

wouterj commented Feb 6, 2016

👍 to enforce a base64 string (specs tell that the nonce should be "16 bytes long and is passed along as a base64 encoded value.") and use a hash function for the filename.

Can you still make these changes, @mattjanssen? Otherwise, we'll take this PR over (while trying to keep your credits).

@mattjanssen
Copy link
Contributor Author

@wouterj You're totally welcome to take charge on this PR. Don't worry about credit :) But thank you for the consideration. I'll keep watch to make sure the original issue is ultimately addressed, too.

@wouterj
Copy link
Member

wouterj commented Feb 6, 2016

Alright, see #6234 for the finished PR.

@wouterj wouterj closed this Feb 6, 2016
xabbuh added a commit that referenced this pull request Feb 7, 2016
…ed) (mattjanssen, WouterJ)

This PR was merged into the 2.3 branch.

Discussion
----------

File System Security Issue in Custom Auth Article (finished)

Finishes #5846

Original description:

 > | Q             | A
 > | ------------- | ---
 > | Doc fix?      | yes
 > | New docs?     | no
 > | Applies to    | all
 > | Fixed tickets | #5845
 >
 > I hope to address this security concern: If `$token->nonce` is set to [ANY USER INPUT] and later we run `file_put_contents($token->nonce, time())` are we allowing hackers to destroy any www-writable file in the system?
 >
 > I did notice that `$nonce` is run through `base64_decode($nonce)` later in the article, implying nonce needs to be a Base64 string. Could this Regex be updated to only accept a Base64 string `[a-zA-Z+/]+={0,2}` for the nonce?
 >
 > At the same time, Base64 allows `/` characters, so `file_put_contents()` would fail in those cases, so even this change, while secure, seems flawed. Replace [+/] with [-_]?

Commits
-------

673fd71 Hash nonce when using as file name
5f125f3 File System Security Issue in Custom Auth Article
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