Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/cose/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "cose/key/rsa"
require "cose/key/symmetric"
require "openssl"
require "uri"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also, worth calling out: this does more than load a constant. The cbor gem only calls URI.parse for CBOR tag 32 if URI is already defined, so this require turns tag-32 parsing on process-wide, which changes how CBOR data decodes everywhere in the app – not just inside cose-ruby. Two things change for any CBOR.decode call:

  • tag-32 values come back as URI objects instead of CBOR::Tagged
  • input that decoded fine before can now raise URI::InvalidURIError
require "cbor"
bytes = CBOR::Tagged.new(32, "https://example.com").to_cbor
CBOR.decode(bytes).class  # => CBOR::Tagged
require "uri"
CBOR.decode(bytes).class  # => URI::HTTPS

Low impact in practice, since Rails and webauthn-ruby load uri anyway. But I think it needs a CHANGELOG entry, and it makes this a minor bump rather than a patch.


module COSE
class Error < StandardError; end
Expand Down Expand Up @@ -52,7 +53,8 @@ def self.deserialize(data)

def self.cbor_decode(data)
CBOR.decode(data)
rescue CBOR::MalformedFormatError, EOFError, FloatDomainError, RegexpError, TypeError, URI::InvalidURIError
rescue CBOR::MalformedFormatError, CBOR::StackError, EOFError, FloatDomainError, RegexpError, TypeError,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
rescue CBOR::MalformedFormatError, CBOR::StackError, EOFError, FloatDomainError, RegexpError, TypeError,
rescue CBOR::UnpackError, EOFError, FloatDomainError, RegexpError, TypeError,

https://github.com/cabo/cbor-ruby/blob/89e94f3b059deb58478eab51996f764fcc6ecd82/doclib/cbor/error.rb#L3-L10

URI::InvalidURIError
raise COSE::MalformedKeyError, "Malformed CBOR key input"
end
end
Expand Down