Skip to content

fix: normalize wallet addresses to lowercase for case-insensitive comparison in attendance functions#21

Open
sirily11 wants to merge 1 commit intomainfrom
fix-error
Open

fix: normalize wallet addresses to lowercase for case-insensitive comparison in attendance functions#21
sirily11 wants to merge 1 commit intomainfrom
fix-error

Conversation

@sirily11
Copy link
Contributor

@sirily11 sirily11 commented Mar 2, 2026

…parison in attendance functions

Copilot AI review requested due to automatic review settings March 2, 2026 05:21
@vercel
Copy link

vercel bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard-chainlab Building Building Preview, Comment Mar 2, 2026 5:21am

Request Review

@autopilot-project-manager autopilot-project-manager bot changed the title fix: normalize wallet addresses to lowercase for case-insensitive com… fix: normalize wallet addresses to lowercase for case-insensitive comparison in attendance functions Mar 2, 2026
@autopilot-project-manager autopilot-project-manager bot added the bug Something isn't working label Mar 2, 2026
@sirily11 sirily11 enabled auto-merge (squash) March 2, 2026 05:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Normalizes Ethereum wallet addresses to lowercase within the public attendance “take” server actions to make signature/address checks and attendant lookups case-insensitive.

Changes:

  • Normalize wallet addresses to lowercase before querying attendant.walletAddress and before persisting newly-registered wallet addresses.
  • Normalize verifyMessage(...) output before comparison to avoid checksum-case mismatches.
  • Add additional server-side logging and switch attendance-record inserts to use returning(...) for inserted IDs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +306 to +323
const insertResult = await db
.insert(attendanceRecord)
.values({
attendanceRoomId: roomId,
attendantId: userInfo.id,
})
.returning({ id: attendanceRecord.id });

console.log("[takeAttendance] New attendant registered", {
attendantId: userInfo.id,
roomId,
insertedRecordId: insertResult[0]?.id,
});

if (!insertResult.length) {
return { error: "Failed to save attendance record" };
}

Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both attendance-record inserts now rely on .returning(...) and treat an empty returned array as a failure. If the underlying libsql/SQLite connection doesn’t return rows for RETURNING (or behavior changes), this will report an error even though the insert may have succeeded, which can lead to confusing UX and potential duplicate records on retry. Prefer treating “no throw” as success, or use an API that returns rowsAffected for success checks, and keep returning only for logging/observability.

Copilot uses AI. Check for mistakes.
Comment on lines +337 to 353
const insertResult = await db
.insert(attendanceRecord)
.values({
attendanceRoomId: roomId,
attendantId: foundAttendant.id,
});
})
.returning({ id: attendanceRecord.id });

return { error: null };
console.log("[takeAttendance] Returning attendant", {
attendantId: foundAttendant.id,
roomId,
insertedRecordId: insertResult[0]?.id,
});

if (!insertResult.length) {
return { error: "Failed to save attendance record" };
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second attendance-record insert uses the same returning + empty-array failure check as above, with the same risk of reporting failure after a successful insert. Consider using a success condition based on thrown errors / rowsAffected, and keep returning optional.

Copilot uses AI. Check for mistakes.
Comment on lines 71 to 100
@@ -82,7 +83,7 @@ export async function getAttendantByWalletAddress(

data = await db.query.attendant.findFirst({
where: and(
eq(attendant.walletAddress, walletAddress),
eq(attendant.walletAddress, normalizedAddress),
eq(attendant.admin, room.createdBy)
),
columns: {
@@ -95,7 +96,7 @@ export async function getAttendantByWalletAddress(
});
} else {
data = await db.query.attendant.findFirst({
where: eq(attendant.walletAddress, walletAddress),
where: eq(attendant.walletAddress, normalizedAddress),
columns: {
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAttendantByWalletAddress* now lowercases the input and compares it directly to attendant.walletAddress. This only becomes truly case-insensitive if the DB values are also guaranteed to be lowercase; otherwise existing attendants (or ones created/updated through other flows that don’t normalize) won’t be found. Consider either normalizing wallet addresses on every write (create/update/import) + backfilling existing rows, or changing the query to compare using SQL lower(wallet_address) so mixed-case stored values still match.

Copilot uses AI. Check for mistakes.
Comment on lines +238 to +239
expected: nonce,
received: previousNonce,
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nonce mismatch path logs both the expected nonce from Redis and the received nonce. Since the nonce is effectively a one-time authentication secret (and here appears shared per room), logging it can weaken the threat model if logs are accessible. Suggest removing the nonce values from logs (or only logging that a mismatch occurred, optionally with a request/room identifier) and keeping detailed values behind an explicit debug flag.

Suggested change
expected: nonce,
received: previousNonce,

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants