I'm following this spec: https://specs.ipfs.tech/ipns/ipns-record/#record-verification
An attacker can create a fake IPNS record with a private key created by the attacker, with the corresponding public key in the IpnsEntry.pubKey field, and with a IpnsEntry.signatureV2 created with that private key. Verification code that literally follows the current spec, can end up accepting the fake IPNS record, since the signature in the record is valid for the public key in the record.
To address this security issue, a step should be added to the verification, where the public key from the record (or from any untrusted source) is compared against the IPNS name. If they don't match, verification must fail.
Note that the Go reference implementation currently already appears to be doing this check:
https://github.com/ipfs/boxo/blob/main/ipns/record.go#L724
I'm following this spec: https://specs.ipfs.tech/ipns/ipns-record/#record-verification
An attacker can create a fake IPNS record with a private key created by the attacker, with the corresponding public key in the IpnsEntry.pubKey field, and with a IpnsEntry.signatureV2 created with that private key. Verification code that literally follows the current spec, can end up accepting the fake IPNS record, since the signature in the record is valid for the public key in the record.
To address this security issue, a step should be added to the verification, where the public key from the record (or from any untrusted source) is compared against the IPNS name. If they don't match, verification must fail.
Note that the Go reference implementation currently already appears to be doing this check:
https://github.com/ipfs/boxo/blob/main/ipns/record.go#L724