Skip to content

Signatures are compared with potentially unsafe == #156

Closed
@drosseau

Description

@drosseau

Signatures are compared with normal string equality as shown here: https://github.com/oauth-xx/oauth-ruby/blob/master/lib/oauth/signature/base.rb#L54. Ruby string comparisons are done with memcmp so this could potentially leak timing info although this will vary depending on the memcmp implementation.

In reality, the chance of this being exploited is very low - it should be basically nil with proper nonce and timestamp checking by the users of this library (unless they're using the PLAINTEXT signature method) - but it is probably worth while to ensure this comparison is constant time.

I saw a pretty straightforward comparison function that would work used here

def safe_compare a, b
  check = a.bytesize ^ b.bytesize
  a.bytes.zip(b.bytes) { |x, y| check |= x ^ y.to_i }
  check == 0
end

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions