veraison / go-cose

go library for CBOR Object Signing and Encryption (COSE)
Mozilla Public License 2.0
50 stars 26 forks source link

Invalid COSE_Sign1 messages are not rejected #29

Closed qmuntal closed 2 years ago

qmuntal commented 2 years ago

First issue spotted by the fuzz tests!

Sign1Message.UnmarshalCBOR does not check that the message strictly follows the COSE_Sign1 definition. It does check for the presence of COSE_Sign1_Tagged

What did you do?

package main

import "github.com/veraison/go-cose"

func main() {
    b := []byte("҄\xf7\xf7\xf7\xf7")
    var msg cose.Sign1Message
    err := msg.UnmarshalCBOR(b)
    if err == nil {
        panic("error expected!")
    }
}

What did you expect to see?

UnmarshalCBOR returns an error due to malformed COSE_Sign1 message

What did you see instead?

UnmarshalCBOR does not return an error.

Notice that the []byte("҄\xf7\xf7\xf7\xf7") input has a valid COSE_Sign1_Tagged prefix but an invalid protected header, as per RFC8152, Section 3

shizhMSFT commented 2 years ago

Addressed by #30