Skip to content

JSON.parse on data before passing verification #275

@emanuelb

Description

@emanuelb

The call to const json = JSON.parse(jsonB64); in line 19 is done before the verification of the data in if (result) in line 30

const json = JSON.parse(jsonB64);
// @ts-ignore
const sig = new KJUR.crypto.Signature({ alg: sigalg, prov: 'cryptojs/jsrsa' });
sig.init({ xy: pubkey, curve });
sig.updateString(jsonB64);
const result = sig.verify(signature);
if (result) {
resolve(json);
} else {
reject('invalid ECDSA signature');
}

thus even not verified data will be passed to JSON.parse (which can be invalid or try to trigger DOS/other attacks)

fix:
call to JSON.parse only if verification successful (line 31 inside the if (result) block)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions