Make secure_compare fail on undef or empty string #1292
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Make secure_compare fail if either of its arguments are not defined or an empty string
Motivation
secure_compare is most likely to be used in a security context but (undef, undef), (undef, '') and ('', '') all return true. This means that an error in the configuration file (e.g. typo in hash key) could lead to unexpected success as the undefined value from the error would be regarded as equal to the lack of credentials from the client (e.g. Basic authentication in an under route).
I know this goes against what Perl regards as equal (especially two empty strings). May still be worth doing from a security perspective though.. can't think of any reason you would intentionally use an empty string in this context.
Possibly important but this implementation fails faster for ('', '1') than ('1', ''), which violates the "constant compare" time I think?