Repository navigation
Normalize malformed nested key errors - #79
OskarEichler wants to merge 3 commits into
Conversation
| 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, |
There was a problem hiding this comment.
| rescue CBOR::MalformedFormatError, CBOR::StackError, EOFError, FloatDomainError, RegexpError, TypeError, | |
| rescue CBOR::UnpackError, EOFError, FloatDomainError, RegexpError, TypeError, |
| require "cose/key/rsa" | ||
| require "cose/key/symmetric" | ||
| require "openssl" | ||
| require "uri" |
There was a problem hiding this comment.
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
URIobjects instead ofCBOR::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::HTTPSLow 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.
|
Addressed in c0d2d46. The rescue now uses CBOR::UnpackError, with a regression that first confirms the nested payload raises CBOR::StackError and then checks COSE normalizes it. Added an Unreleased changelog entry explicitly documenting that requiring uri enables tag-32 decoding process-wide, including the effect on callers outside COSE, and noting the minor-release implication. No release/version bump was made. Validation on Ruby 4.0.6: 87 examples, zero failures; targeted RuboCop and git diff --check pass. Bundler selected unicode-emoji 4.3.0 locally; that unrelated lockfile change was not committed. |
Loads URI explicitly and converts deeply nested CBOR stack failures into COSE::MalformedKeyError alongside the other malformed-input exceptions.
Verified with 86 upstream examples plus focused malformed-key, WebAuthn, and Rails integration models.