Skip to content

Reject RSVPs to events that don't exist and stop trusting the per_ID sent by the client - #12

Merged
davis-brown merged 2 commits into
mainfrom
factory/issue-10
Nov 24, 2026
Merged

davis-brown merged 2 commits into
mainfrom
factory/issue-10

Conversation

@davis-brown

Copy link
Copy Markdown
Owner

Closes #10

POST /api/attendee now returns 404 for events that don't exist, and it sets per_ID on the server instead of taking it from the request. The new tests and the existing backend tests pass. I didn't run the browser checks.

What changed

In exports.create in backend/controllers/attendee.controller.js:

  • Event check: it looks up the user and the event (db.event.findByPk(req.body.evt_ID)) together. If the event doesn't exist it answers 404 { message: "Event not found." } and creates nothing.
  • per_ID from the server: it now comes from the logged-in user's linked member, found with db.person.findOne({ where: { user_name: user.username } }), the same lookup authJwt.js and signin use. If the login has no linked member it is null. req.body.per_ID is ignored.
  • Unchanged: updating an existing RSVP, contribution, and refreshAttendance work as before. The last .then now only sends a response if the 404 hasn't already been sent.

How I verified it

  • I added backend/test/attendee.test.js (node:test). It stubs the model methods on require("../models"), so no database is needed. It checks three cases:
    • a missing event gives 404 with the right message, and attendee.create is never called;
    • attendee.create gets the linked person's per_ID (7), not the one in the body (42);
    • a login with no linked member stores per_ID: null.
  • cd backend && npm test passes all 6 tests (3 new, 3 existing). The worktree had no node_modules, so I ran npm ci first; until then both test files failed with Cannot find module 'sequelize'.
  • The backend has no linter, and the frontend, which does, wasn't touched.

What to check

  • When someone updates an RSVP they already have, the change only touches contribution. Old rows that already hold a forged per_ID keep it until the user cancels and RSVPs again. The issue said to leave this path alone, so I didn't add a cleanup.
  • The RSVP → change contribution → cancel flow isn't covered by the unit tests. CI's browser job (calendar.check.js) should cover it.

Codex review

  • backend/controllers/attendee.controller.js:46 Updating an existing RSVP leaves its old per_ID in place. Rows created before this change can still point to another member, and deleting that member deletes the mislinked RSVP. Set the server-resolved per_ID on updates as well as inserts, repair existing mismatches, and add a regression test for the update path.
  • backend/controllers/attendee.controller.js:23 A truthy but invalid evt_ID, such as an array or object, passes the presence check and makes Sequelize return an error that the endpoint sends as a 500. Validate and normalize evt_ID to a positive integer before querying, return 400 for malformed values, and use the normalized ID for both lookup and persistence.

Fixes after the review

I fixed both findings and committed them on HEAD as 5965d08. All 9 backend tests pass (npm test). The backend has no lint script, and I didn't touch the frontend, so I didn't run its lint.

1. Updating an RSVP leaves its old per_ID — fixed.

  • Update path: when a member changes an RSVP, the server now saves their own per_ID along with the new contribution (backend/controllers/attendee.controller.js:46). Before, only new RSVPs got the server's value.
  • Repairing existing rows: new backend/attendee-per-id.js runs once at server startup, after the existing database-upgrade steps. It sets every RSVP's per_ID to the member record linked to its username. It's added to server.js and to the bundle script so it deploys with the backend.
    • It skips rows that have no username, so it can't wipe links it has no way to check.
    • If a row's user has no linked member, per_ID becomes null. That matches what the server now stores for new RSVPs from such users.
    • It only changes rows that don't already match, so running it on every startup is safe.
    • I ran the SQL against a throwaway MySQL 8 with sample rows and it behaved as above. There's no automated test for it.
  • Test: a new test updates an existing RSVP whose per_ID is 42 and checks it is relinked to the caller's 7.

2. A malformed evt_ID gives a 500 — fixed.

  • evt_ID is now converted to a number up front. If it isn't a positive whole number, the request gets a 400 and nothing is saved.
  • The converted value is used for both the event lookup and the saved row.
  • Tests: one checks that missing, array, object, "abc", 0, -1 and 1.5 each get a 400 and create nothing. Another checks that "5" is saved as the number 5.
  • One known gap: a single-element array such as [5] converts to 5 and is accepted. It still ends up as a valid ID, so I left it.

The 400 message changed from "Content can NOT be empty!" to "evt_ID must be a positive integer." Nothing in the frontend checks for the old text.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T20:16:12.856319Z 5965d08 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@davis-brown
davis-brown merged commit 4e84b22 into main Nov 24, 2026
3 checks passed
@davis-brown
davis-brown deleted the factory/issue-10 branch November 24, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reject RSVPs to events that don't exist and stop trusting the per_ID sent by the client

1 participant