Skip to content

Invalid multiple algorithm logic #297

@ereOn

Description

@ereOn

The Validation takes a Vec of Algorithm but the validation code here incorrectly ensures that the JWT's algorithm is compatible with all the specified algorithms, instead of just ensuring it finds at least one that matches.

Put otherwise, this:

  if validation.validate_signature {
        for alg in &validation.algorithms {
            if key.family != alg.family() {
                return Err(new_error(ErrorKind::InvalidAlgorithm));
            }
        }
    }

Should be more like:

  if validation.validate_signature {
        for alg in &validation.algorithms {
            if key.family == alg.family() {
                // Success: let's move on.
            }
        }

        return Err(new_error(ErrorKind::InvalidAlgorithm));
   }

As it stands, it is impossible to use more than one algorithm in a validation because of this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions