Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate that fid on username add message matches fid on ens proof #2378

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-cheetahs-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farcaster/hubble": patch
---

fix: validate that fid on username add message matches fid on ens proof
37 changes: 37 additions & 0 deletions apps/hubble/src/storage/engine/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,43 @@ describe("mergeMessage", () => {
expect(result._unsafeUnwrapErr().message).toMatch("failed to resolve ens");
});

test("fails when fid on message doesn't match fid on ens name proof", async () => {
const fid2 = Factories.Fid.build();
const signer2 = Factories.Ed25519Signer.build();
const custodySigner2 = Factories.Eip712Signer.build();
const signerKey2 = (await signer2.getSignerKey())._unsafeUnwrap();
const custodySignerKey2 = (await custodySigner2.getSignerKey())._unsafeUnwrap();
const custodyEvent2 = Factories.IdRegistryOnChainEvent.build(
{ fid: fid2 },
{ transient: { to: custodySignerKey2 } },
);
const signerAddEvent2 = Factories.SignerOnChainEvent.build(
{ fid: fid2 },
{ transient: { signer: signerKey2 } },
);
const storageEvent2 = Factories.StorageRentOnChainEvent.build({ fid: fid2 });
await engine.mergeOnChainEvent(custodyEvent2);
await engine.mergeOnChainEvent(signerAddEvent2);
await engine.mergeOnChainEvent(storageEvent2);

const spoofedUserDataAdd = await Factories.UserDataAddMessage.create(
{
data: {
fid: fid2,
userDataBody: {
type: UserDataType.USERNAME,
value: "test123.eth",
},
},
},
{ transient: { signer: signer2 } },
);

const result = await engine.mergeMessage(spoofedUserDataAdd);
expect(result).toMatchObject(err({ errCode: "bad_request.validation_failure" }));
expect(result._unsafeUnwrapErr().message).toMatch(`fid ${fid} does not match message fid ${fid2}`);
});

test("revokes the user data add when the username proof is revoked", async () => {
const result = await engine.mergeMessage(userDataAdd);
expect(result.isOk()).toBeTruthy();
Expand Down
31 changes: 18 additions & 13 deletions apps/hubble/src/storage/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1279,23 +1279,28 @@
return err(nameProof.error);
}

if (nameProof.value.type === UserNameType.USERNAME_TYPE_FNAME) {
// Check that the fid for the fname and message are the same
if (nameProof.value.fid !== message.data.fid) {
return err(
new HubError(
"bad_request.validation_failure",
`fname fid ${nameProof.value.fid} does not match message fid ${message.data.fid}`,
),
);
}
} else if (nameProof.value.type === UserNameType.USERNAME_TYPE_ENS_L1) {
if (
nameProof.value.type !== UserNameType.USERNAME_TYPE_FNAME &&
nameProof.value.type !== UserNameType.USERNAME_TYPE_ENS_L1
) {
return err(new HubError("bad_request.validation_failure", "invalid username type"));

Check warning on line 1286 in apps/hubble/src/storage/engine/index.ts

View check run for this annotation

Codecov / codecov/patch

apps/hubble/src/storage/engine/index.ts#L1286

Added line #L1286 was not covered by tests
}

// Check that the fid for the fname/ens name and message are the same
if (nameProof.value.fid !== message.data.fid) {
return err(
new HubError(
"bad_request.validation_failure",
`fid ${nameProof.value.fid} does not match message fid ${message.data.fid}`,
),
);
}

if (nameProof.value.type === UserNameType.USERNAME_TYPE_ENS_L1) {
const result = await this.validateEnsUsernameProof(nameProof.value, custodyAddress);
if (result.isErr()) {
return err(result.error);
}
} else {
return err(new HubError("bad_request.validation_failure", "invalid username type"));
}
}
}
Expand Down
Loading