Skip to content

Commit

Permalink
Fix maskedSubject attack vector and timestamp bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Aug 20, 2024
1 parent 853a4dd commit 1455cd2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/contracts/src/EmailAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ contract EmailAuth is OwnableUpgradeable, UUPSUpgradeable {
emailAuthMsg.proof.timestamp > lastTimestamp,
"invalid timestamp"
);
require(
bytes(emailAuthMsg.proof.maskedSubject).length <=
verifier.SUBJECT_BYTES(),
"invalid masked subject length"
);
require(
emailAuthMsg.skipedSubjectPrefix < verifier.SUBJECT_BYTES(),
"invalid size of the skiped subject prefix"
);

// Construct an expectedSubject from template and the values of emailAuthMsg.subjectParams.
string memory expectedSubject = SubjectUtils.computeExpectedSubject(
Expand All @@ -241,7 +250,9 @@ contract EmailAuth is OwnableUpgradeable, UUPSUpgradeable {
);

usedNullifiers[emailAuthMsg.proof.emailNullifier] = true;
lastTimestamp = emailAuthMsg.proof.timestamp;
if (timestampCheckEnabled) {
lastTimestamp = emailAuthMsg.proof.timestamp;
}
emit EmailAuthed(
emailAuthMsg.proof.emailNullifier,
emailAuthMsg.proof.accountSalt,
Expand Down

0 comments on commit 1455cd2

Please sign in to comment.