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

fix(Security): Don't attempt empty secret fallback on >=v3 ciphertext #46176

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

joshtrichards
Copy link
Member

@joshtrichards joshtrichards commented Jun 27, 2024

Summary

The v3 ciphertext format (added in #23496) has never worked with an empty secret/password. However, the v3 implementation was added prior to the existence of the empty secret fallback code added in #31499.

While looking into #34012 I noted that the only reason the hash_hkdf() PHP ValueError is occurring is because the fallback is being attempted not only anytime the initial decrypt attempt fails, but also against newer ciphertext versions (where the fallback isn't relevant).

This PR adjusts the fallback logic to only run against <=2 versioned or non-versioned (which is even older) ciphertext.

Note: This does not fix the underlying cause of #34012 (which is probably in at least most cases a configuration problem), but it does:

  • clean-up the logic to avoid the PHP error
  • avoids doing the fallback on newer ciphertext where it's pointless (and most ciphertext is probably v3 at this point)

References:

TODO

  • Adjust the tests (since I also change one of the Exception strings)
  • Add a test (for the fallback; I don't believe there is one but need to double-check again)

Checklist

Signed-off-by: Josh <josh.t.richards@gmail.com>
@joshtrichards
Copy link
Member Author

/backport to stable29

@joshtrichards
Copy link
Member Author

/backport to stable28

@joshtrichards joshtrichards added this to the Nextcloud 30 milestone Jun 27, 2024
Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
$version = $parts[3];
}

if ((!empty($version) && $version <= '2') || empty($version)) { // only <3 versioned or old non-versioned ciphertext ever supported empty secrets
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if ((!empty($version) && $version <= '2') || empty($version)) { // only <3 versioned or old non-versioned ciphertext ever supported empty secrets
if (empty($version) || $version <= '2') { // only <3 versioned or old non-versioned ciphertext ever supported empty secrets

Comment on lines -113 to -115
if ($partCount < 3 || $partCount > 4) {
throw new Exception('Authenticated ciphertext could not be decoded.');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this removed?
Should be added back.

This was referenced Jul 30, 2024
This was referenced Aug 5, 2024
@skjnldsv skjnldsv mentioned this pull request Aug 13, 2024
@skjnldsv skjnldsv modified the milestones: Nextcloud 30, Nextcloud 31 Aug 14, 2024
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.

3 participants