Skip to content

Stop recording where organizers connect from - #74

Merged
Flatts3000 merged 4 commits into
mainfrom
fix-70-stop-storing-organizer-ip
Aug 30, 2026
Merged

Flatts3000 merged 4 commits into
mainfrom
fix-70-stop-storing-organizer-ip

Conversation

@Flatts3000

@Flatts3000 Flatts3000 commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Part one of #70, and deliberately not the whole of it.

audit_log recorded an IP address and a browser string against every authenticated write, and against every login and logout. Neither was ever read: the admin audit view at admin.service.ts:589 selects its columns explicitly and includes neither, the seed writes neither, and no test referenced either. Write-only data, held indefinitely, with no prune path.

Joined against users (email, required and unique) and the membership tables, those columns made a durable map of organizer email -> which group they run -> IP address -> activity timeline - for exactly the population slide 4 of the partner deck cites as facing prosecution.

Why this stops short of dropping the columns

The first version of this PR dropped them in the same release. That breaks production.

deploy/deploy.sh migrates while the previous backend containers are still serving - deliberately, so a failed migration cannot leave new code on an old schema. But the old image's logAuditEvent always passes ipAddress (null at worst, never undefined), so Drizzle names ip_address in every audit INSERT. The moment the column goes, every authenticated write 500s, and POST /api/auth/verify fails after consuming the magic link, so the user is left with no token and a spent link.

The sharper problem is the rollback. deploy.sh restores the previous image by tag if the health gate fails - which would restore a backend that cannot log anyone in, against an already-migrated schema. The recovery mechanism would create a permanent outage instead of ending one.

So: expand/contract. This release stops writing the columns. A follow-up drops them, deployed after this code is live. #70 stays open until then.

What changed

logAuditEvent no longer collects either field, and the schema stops declaring them.

That made the req parameter dead - it existed only to reach req.ip - so it came out too, and the compiler found every consumer: 31 req properties, 27 unused parameters, 29 call-site arguments, 6 Request imports. Every removal was driven by a TypeScript error rather than by grep, and noUnusedParameters is on, so leaving the plumbing was not an option anyway.

middleware/audit.ts keeps its own req, which it genuinely uses for path and method.

Tests

audit.service.test.ts reads the raw columns with SQL rather than through the Drizzle model, because the model no longer declares them and the point is what reaches the table. It proves every row written now leaves both fields null, and that sign-in and sign-out still record without a request object.

Also dropped from this PR

The deck change and the widened privacy claim went with the migration. The claim was wrong regardless: authLoginRateLimiter and authVerifyRateLimiter use express-rate-limit's default key generator, which keys on raw req.ip and holds it in the memory store for the full fifteen-minute window - the file's own comment says so. "No IP addresses for anyone at all" is not true of the authenticated surface, and the deck will be corrected alongside the column drop.

Verification

152 backend tests pass, up from 149. Lint and typecheck clean. Migration journal back to 11 entries and validated. Verified against a test database recreated from scratch, so the columns are genuinely present and genuinely empty.

`audit_log` recorded an IP address and a browser string against every authenticated write, and against every login and logout. Neither was ever read: the admin audit view at `admin.service.ts:589` selects its columns explicitly and includes neither, the seed writes neither, and no test referenced either. Write-only data, held indefinitely, with no prune path.

Joined against `users` (email, required and unique) and the membership tables, those columns made a durable map of **organizer email -> which group they run -> IP address -> activity timeline** - for exactly the population slide 4 of the partner deck cites as facing prosecution.

## What changed

The columns are dropped, which takes the historical values with them. `logAuditEvent` no longer collects either.

That made the `req` parameter dead. It existed only to reach `req.ip`, so it came out too, and the compiler found every consumer: **31 `req` properties, 27 unused parameters, 29 call-site arguments, 6 `Request` imports.** Every removal was driven by a TypeScript error rather than by grep, and `noUnusedParameters` is on, so leaving the plumbing in place was not an option anyway - a `req` threaded through the service layer for no reason is precisely the trap the next person falls into.

The audit middleware keeps its own `req`, which it genuinely uses for path and method.

## Why removal rather than truncation or a retention window

The issue offered three options. Removal is the one the project's own stated principles pick: *"Data never collected cannot be leaked."* An audit entry is already attributable through `userId`, which is the accountability the log exists for. Truncating or expiring a field nothing reads would have been ceremony.

## Tests

`audit.service.test.ts` asserts against `information_schema` rather than against the service, because deleting the code that writes a column leaves the column behind. It also checks the table did not simply vanish, and that sign-in and sign-out still record without a request object.

## The deck had to change with it

Slide 10 disclosed the IP and browser string two days ago. That disclosure is now false, so it says what is actually stored - an email and a group - and the "what is not there" column widens to **IP addresses or cookies for anyone at all**.

That wider claim was verified before making it: `request-logger.ts` writes only timestamp, request id, method and path, and the rate limiter hashes into an in-memory store that is never persisted and never holds a raw address. So no IP reaches the database or the application logs.

## Verification

- 152 backend tests pass, up from 149
- lint and typecheck clean
- migration journal validated: 12 migrations, sequential, all snapshots parseable
- deck swept in Chromium and WebKit at 1440x900, 901x640, 430x932 and 320x700, all 15 slides
- the deck's counted test figure moved 188 -> 191 on its own, which is the CI check from #69 doing its job
CI re-applies every migration against an already-migrated database to prove
they are idempotent. drizzle-kit generates a bare DROP COLUMN, which succeeds
once and then fails with 'column "ip_address" of relation "audit_log" does
not exist' - which is exactly what the job caught.

Every other migration in the tree already follows the convention; the NOTICE
lines in that job's log are the other ten skipping cleanly. This one now uses
DROP COLUMN IF EXISTS, with a comment saying why so the next generated
migration does not repeat it.

Proven locally the way CI does it: apply all migrations to an empty database,
then re-apply every .sql file by hand. No failures, and the audit_log table is
left with zero ip_address or user_agent columns.
`audit_log` recorded an IP address and a browser string against every authenticated write, and against every login and logout. Neither was ever read: the admin audit view at `admin.service.ts:589` selects its columns explicitly and includes neither, the seed writes neither, and no test referenced either. Write-only data, held indefinitely, with no prune path.

Joined against `users` (email, required and unique) and the membership tables, those columns made a durable map of **organizer email -> which group they run -> IP address -> activity timeline** - for exactly the population slide 4 of the partner deck cites as facing prosecution.

## Why this stops short of dropping the columns

The first version of this PR dropped them in the same release. That breaks production.

`deploy/deploy.sh` migrates while the **previous** backend containers are still serving - deliberately, so a failed migration cannot leave new code on an old schema. But the old image's `logAuditEvent` always passes `ipAddress` (null at worst, never `undefined`), so Drizzle names `ip_address` in every audit INSERT. The moment the column goes, every authenticated write 500s, and `POST /api/auth/verify` fails *after* consuming the magic link, so the user is left with no token and a spent link.

The sharper problem is the rollback. `deploy.sh` restores the previous image by tag if the health gate fails - which would restore a backend that cannot log anyone in, against an already-migrated schema. The recovery mechanism would create a permanent outage instead of ending one.

So: expand/contract. **This release stops writing the columns. A follow-up drops them, deployed after this code is live.** #70 stays open until then.

## What changed

`logAuditEvent` no longer collects either field, and the schema stops declaring them.

That made the `req` parameter dead - it existed only to reach `req.ip` - so it came out too, and the compiler found every consumer: **31 `req` properties, 27 unused parameters, 29 call-site arguments, 6 `Request` imports.** Every removal was driven by a TypeScript error rather than by grep, and `noUnusedParameters` is on, so leaving the plumbing was not an option anyway.

`middleware/audit.ts` keeps its own `req`, which it genuinely uses for path and method.

## Tests

`audit.service.test.ts` reads the raw columns with SQL rather than through the Drizzle model, because the model no longer declares them and the point is what reaches the table. It proves every row written now leaves both fields null, and that sign-in and sign-out still record without a request object.

## Also dropped from this PR
CI caught two constraints the first split missed, and both are correct.

The repository enforces that the Drizzle schema and the migrations describe the
same database: the Migrations job builds a schema from the SQL and another from
drizzle-kit push, then diffs them, and Test Backend re-runs generate to prove
meta/ is not stale. Removing the column declarations without a migration breaks
both, because the schema then says one thing and the migrations another.

So the columns stay declared. Nothing writes them - that is the whole change -
and the declaration carries a comment saying why they are still there and what
removes them. Dropping them still has to wait for a second deploy, because
deploy.sh migrates while the previous backend is serving and that image names
ip_address in every audit INSERT.

The test assertion moved with it. Asserting the field is absent from the model
was right when the model did not declare it; now the honest assertion is that
nothing puts a value in either column, which is what the release actually
guarantees.

Also rebuilt the deck, whose counted test figure moved 188 to 191 with the three
new tests. That was the third failure, and it is the check from #69 doing
exactly what it was added for.
@Flatts3000
Flatts3000 merged commit f35b70e into main Aug 30, 2026
12 checks passed
@Flatts3000
Flatts3000 deleted the fix-70-stop-storing-organizer-ip branch August 30, 2026 17:53
Flatts3000 added a commit that referenced this pull request Aug 30, 2026
* Drop the audit log's IP and user agent columns

#74 stopped anything writing `ip_address` and `user_agent`, and that code is deployed. Dropping the columns is now safe, because the image currently serving does not name them in its INSERTs. Doing both at once would have broken production: `deploy.sh` migrates while the previous backend is still serving, and the rollback path restores that same image against the already-migrated schema.

## What changed

The migration drops both columns, taking whatever history they held with them. The schema stops declaring them. The comment left in their place says why they are gone, so the next person to reach for a convenient `req.ip` finds the reasoning rather than an absence.

The migration uses `DROP COLUMN IF EXISTS`. CI re-applies every migration against an already-migrated database to prove idempotency, and drizzle-kit generates a bare `DROP COLUMN`, which succeeds once and then errors - that is how the first attempt at this failed.

## Tests

The assertion moves from values to schema. Reading `information_schema` is the stronger guarantee: deleting the code that writes a column leaves the column behind, and the test now fails if it ever comes back. It also checks the table did not simply vanish, which is how that kind of assertion passes for the wrong reason.

## The deck, and a claim it was going to get wrong

Slide 10 disclosed the IP and browser string. That is now false, so it says what is actually kept: an email, and which group they work with.

The "what is not there" line widens to **IP addresses or cookies in anything Relay stores**, which is narrower than the phrasing I first wrote. "For anyone at all" would have been wrong: `authLoginRateLimiter` and `authVerifyRateLimiter` use express-rate-limit's default key generator, which keys on raw `req.ip` and holds it in memory for the full fifteen-minute window. The file's own comment says so.

Rather than quietly narrow the wording, that now appears in the slide's known-limits line, next to the routing metadata Relay already volunteers: the login rate limiter holds a caller address in memory for fifteen minutes to make brute-forcing a sign-in expensive, and neither is written down.

`docs/prd_to_mvp_plan.md` still listed `ip_address` in its record of the schema. Removed.

## Verification

- test database dropped and rebuilt from scratch, then every migration re-applied by hand: no failures, and `audit_log` ends with neither column
- 152 backend tests pass, lint and typecheck clean

* Stop the access log recording who browses the directory

Four findings. The first is not a deck wording problem, it is a live violation
of a constraint CLAUDE.md calls non-negotiable.

nginx's stock access log format ends with $http_user_agent and
$http_x_forwarded_for, and Caddy appends the real client address to
X-Forwarded-For before proxying. Only the health-check location set access_log
off. So every page load wrote the visitor's IP and browser string to stdout,
which Docker's default json-file driver persists on the host unrotated - no
logging options are set in the compose file.

Verified by request rather than by reading: GET /directory logged
"Mozilla/5.0 TestBrowser" "203.0.113.77". That is who browsed the public
directory, which CLAUDE.md forbids in as many words, and the deck was about to
deny it in the same release.

A log_format carrying only time, request, status, size and duration replaces it.
Same request now logs none of the three identifying strings. $remote_addr is
omitted as well: it is only ever Caddy's container address, so it identifies
nothing while reading as though it might.

The deck also lost a disclosure it should have kept. Trimming the organizer line
to an email and a group removed the activity trail along with the IP -
auditMiddleware still records every authenticated write plus sign-in and
sign-out against a user id and timestamp, and nothing prunes it. The line says
so again.

The known-limits sentence contradicted itself inside one clause: it said the
routing metadata is stored in the clear and then that neither limit is written
down, immediately before an existing sentence using the same phrase to mean
documented. Rewritten.

And an assertion in the new test could not fail: db.select projects whatever the
Drizzle model declares, so checking the returned keys lack ipAddress would pass
even if the migration had never run. Removed, with a note pointing at the
information_schema assertion that is the real guarantee.
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.

1 participant