fix: typed data with a missing field or a bool that is not true or false is refused (closes #552)
ethers signs a bool field by whether its value is truthy, so the string "false" was shown as false and signed as true, and a bool field left out was shown as nothing and signed as false. The sign screen now refuses typed data whose message leaves out a declared field, at any level of nesting, or holds a bool that is not true or false: the error line names the field and Sign is disabled. The background refuses a signature for it too. Presence is an own-key test, so a field named like a built-in property such as constructor is not found by accident. signedPrimaryType() moves to the shared module so the background reads the message as the same type. Model: opus-5-5
This commit is contained in:
@@ -384,13 +384,13 @@ function loadBackground(options) {
|
||||
|
||||
// The same through eth_signTypedData_v4, whose params name the address
|
||||
// first and the typed data second.
|
||||
function requestTypedData() {
|
||||
function requestTypedData(typedData = TYPED_DATA) {
|
||||
let rpcResult = null;
|
||||
messageListener(
|
||||
{
|
||||
type: "AUTISTMASK_RPC",
|
||||
method: "eth_signTypedData_v4",
|
||||
params: [signer.address, TYPED_DATA],
|
||||
params: [signer.address, typedData],
|
||||
},
|
||||
{ origin: ORIGIN },
|
||||
(r) => {
|
||||
@@ -1494,8 +1494,8 @@ describe("what the approval is verified against", () => {
|
||||
// screen; a signature for it that reaches the background anyway is not
|
||||
// handed to the page (https://git.eeqj.de/sneak/AutistMask/issues/519).
|
||||
// TYPED_DATA names mainnet.
|
||||
async function answerTypedData(bg, pending) {
|
||||
const { domain, types, message } = JSON.parse(TYPED_DATA);
|
||||
async function answerTypedData(bg, pending, typedData = TYPED_DATA) {
|
||||
const { domain, types, message } = JSON.parse(typedData);
|
||||
delete types.EIP712Domain;
|
||||
const signature = await signer.signTypedData(domain, types, message);
|
||||
const answer = bg.send(
|
||||
@@ -1539,6 +1539,42 @@ describe("what the approval is verified against", () => {
|
||||
expect(pending.result()).toEqual({ error: { message: refusal } });
|
||||
});
|
||||
|
||||
// ethers signs a `bool` field sent as the string "false" as true, and one
|
||||
// left out as false. The sign screen refuses both; a signature for either
|
||||
// that reaches the background anyway is not handed to the page
|
||||
// (https://git.eeqj.de/sneak/AutistMask/issues/552).
|
||||
test.each([
|
||||
[
|
||||
'"false"',
|
||||
"false",
|
||||
'The field "approved" is not true or false, so this typed data cannot be signed.',
|
||||
],
|
||||
[
|
||||
"left out",
|
||||
undefined,
|
||||
'The field "approved" is missing from the message, so this typed data cannot be signed.',
|
||||
],
|
||||
])(
|
||||
"typed data with a bool %s is refused, not handed back",
|
||||
async (_, approved, refusal) => {
|
||||
const data = JSON.parse(TYPED_DATA);
|
||||
data.types.Note.push({ name: "approved", type: "bool" });
|
||||
data.message.approved = approved;
|
||||
const typedData = JSON.stringify(data);
|
||||
const bg = loadBackground();
|
||||
const pending = bg.requestTypedData(typedData);
|
||||
await settle();
|
||||
|
||||
const { answer } = await answerTypedData(bg, pending, typedData);
|
||||
|
||||
expect(answer.sendResponse).toHaveBeenCalledWith({
|
||||
error: refusal,
|
||||
retryable: false,
|
||||
});
|
||||
expect(pending.result()).toEqual({ error: { message: refusal } });
|
||||
},
|
||||
);
|
||||
|
||||
test("a sign request from another address raises no approval at all", async () => {
|
||||
const bg = loadBackground();
|
||||
const pending = bg.requestSign(other.address);
|
||||
|
||||
Reference in New Issue
Block a user