Skip to content

Fix GPG nonce UUID validation using incorrect operand#592

Open
flightlesstux wants to merge 1 commit intopassbolt:masterfrom
flightlesstux:fix/gpg-nonce-uuid-validation-logic
Open

Fix GPG nonce UUID validation using incorrect operand#592
flightlesstux wants to merge 1 commit intopassbolt:masterfrom
flightlesstux:fix/gpg-nonce-uuid-validation-logic

Conversation

@flightlesstux
Copy link
Copy Markdown

Problem

In GpgAuthenticator::_checkNonce(), the UUID validation check compares the wrong operand:

// Before — semantically wrong
if ($version != Validation::uuid($uuid)) {

Validation::uuid() returns a boolean (true/false), not the UUID string. The variable being compared is $version — the protocol string 'gpgauthv1.3.0' — which has nothing to do with UUID validation.

This works today only because PHP loose type coercion happens to produce the correct boolean outcome:

  • Valid UUID → Validation::uuid() returns true'gpgauthv1.3.0' != truefalse → no error ✓
  • Invalid UUID → Validation::uuid() returns false'gpgauthv1.3.0' != falsetrue → error triggered ✓

However, this is a fragile coincidence. If Validation::uuid() ever returns a non-boolean (e.g., the validated string itself), the check would silently stop rejecting invalid UUIDs in the GPG authentication flow.

Fix

Replace the accidental loose comparison with a direct boolean check on the validation result:

// After — explicit and correct
if (!Validation::uuid($uuid)) {

Impact

  • The authentication behaviour is unchanged in the current PHP/CakePHP version
  • The fix makes the intent explicit and removes reliance on accidental type coercion
  • Prevents a silent security regression if the validation helper's return type changes

The _checkNonce() method compared $version (the protocol string
'gpgauthv1.3.0') against the return value of Validation::uuid(),
which returns a boolean. This worked accidentally via PHP loose
type coercion but is semantically wrong: any future change to the
return type of Validation::uuid() would silently disable UUID
validation entirely.

Replace the loose comparison against $version with a direct boolean
check on Validation::uuid($uuid).
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 12, 2026

CLA assistant check
All committers have signed the CLA.

@stripthis
Copy link
Copy Markdown
Member

@flightlesstux Looks good. Good catch.

@flightlesstux
Copy link
Copy Markdown
Author

@flightlesstux Looks good. Good catch.

Thank you!

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