Repository navigation
Fix the vote outage; move server-only helpers out of the shared barrel - #285
Merged
Merged
Conversation
Its only caller is server/api/email.post.ts, but the shared helpers barrel put the Gemini SDK into the client module graph. The response schema moves to server/utils/schema.ts as SpamFilterResponseSchema, rather than becoming a server-wide auto-import named ResponseSchema. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RE7Gq8fzzVAfBahzvcUqTP
The shared useDirectus composable received raw IPs and hashed them through a dynamic node:crypto import, so the client bundle would not break. The vote route now hashes once and passes only the hash, and getRecentRatingByIP becomes getRecentRatingByIPHash. Hashes are byte-identical to before, which test/ipProcessing.test.ts now pins, since stored ratings carry them. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RE7Gq8fzzVAfBahzvcUqTP
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RE7Gq8fzzVAfBahzvcUqTP
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused refactor preserves hashing behavior, updates affected callers consistently, and has no identified blocking issues.
No open issues 🎉
What changed in this PR
Moves server-only helpers out of the shared client/server barrel and hashes vote IPs in the server route while preserving existing cooldown hashes.
Changes:
- Relocates spam filtering and IP processing to server utilities.
- Updates voting interfaces to accept hashes instead of raw IPs.
- Adds hash regression tests and documents verification and deferred work.
| File | Description |
|---|---|
nuxt-app/test/vote.route.test.ts |
Checks exact hashes and invalid-IP handling. |
nuxt-app/test/ipProcessing.test.ts |
Adds hash compatibility regression tests. |
nuxt-app/server/utils/schema.ts |
Houses the renamed spam-response schema. |
nuxt-app/server/utils/ipProcessing.ts |
Uses synchronous, server-only Node imports. |
nuxt-app/server/utils/index.ts |
Exports the relocated helpers. |
nuxt-app/server/utils/aiSpamFilter.ts |
Uses the centralized response schema. |
nuxt-app/server/api/vote.post.ts |
Hashes IPs before calling the composable. |
nuxt-app/server/api/email.post.ts |
Imports spam filtering from server utilities. |
nuxt-app/helpers/index.ts |
Removes server-only exports. |
nuxt-app/composables/useDirectus.ts |
Stores and queries precomputed IP hashes. |
docs/dependency-upgrade-plan.md |
Records completion and the deferred mapped-IPv6 issue. |
Review effort: Balanced
Every vote with an IP has failed with 500 since the cooldown shipped: useDirectus talks to the CMS without a token, and the public role may create ratings but not read their ip or target. The CMS answered 403 before the insert, so no vote was stored. getRecentRatingByIPHash and updateRatingVote move to useAuthenticatedDirectus. createRating stays public. The route test now mocks both clients separately; one mock for both is how the tests stayed green over the outage. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RE7Gq8fzzVAfBahzvcUqTP
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RE7Gq8fzzVAfBahzvcUqTP
…o infrastructure-improvements
Directus permissions are not in the repo, so the grants made by hand for the vote cooldown are written down here. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RE7Gq8fzzVAfBahzvcUqTP
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Two server-only helpers lived in
helpers/, the barrel shared by client and server code. Both move toserver/utils/.aiSpamFilter: its only caller isserver/api/email.post.ts. It moves unchanged, except thatResponseSchemagoes toserver/utils/schema.tsasSpamFilterResponseSchema. Exported fromserver/utils/under its old name, it would have become a server-wide auto-import with a generic name.ipProcessing: the shareduseDirectuscomposable received raw IPs and hashed them, loadingnode:cryptothrough a dynamicimport()so that the client bundle would not break. Nowserver/api/vote.post.tshashes once and passes only the hash.createRatingstores it as given, andgetRecentRatingByIPbecomesgetRecentRatingByIPHash(podcast, ipHash, since). With static imports, the helper is synchronous.The preview test returned 500, and the cause was not this PR. Since the cooldown shipped in
cd9acca, every vote with an IP has failed, in production too, and none was stored.useDirectustalks to the CMS without a token, so the cooldown lookup ran as the public role.iportarget, so the CMS answered403 FORBIDDEN. The same 403 reproduces with a plain unauthenticated request.Fix:
getRecentRatingByIPHashandupdateRatingVotemove touseAuthenticatedDirectus()(the API token).createRatingstays on the public client, which may create. Opening the public role instead would expose the IP hashes to anyone.Tests: the route test now mocks the two clients separately. A single mock stood in for both before, which is how the tests stayed green through the outage. Negative control: with the lookup back on the public client, 4 tests fail. Locally without a token, a vote fails with
NUXT_DIRECTUS_API_TOKEN not configured, which shows the token path is taken.Requires the token's role to have
readandupdateonratings, includingipandtarget. Verify on the preview: vote, then vote the opposite way within 10 minutes, and expect exactly one rating with the second direction.Why the hashes matter, and how they were kept identical
Stored ratings carry these hashes, and the 10-minute vote cooldown matches on them. A changed hash would split the cooldown across the deploy.
::1,::ffff:, a zone index, whitespace, three invalid inputs). The moved helper produces identical output for all of them.test/ipProcessing.test.tspins those values.test/vote.route.test.tsnow asserts the exact hash passed to the composable, and adds a case for an invalid IP (no cooldown lookup, noipstored).Verification
node:cryptoandnode:netbeing externalized for the browser are gone. The client bundle contains none of the moved code.prettier:checkclean.lint0 errors, 168 warnings (unchanged).test347/347 (11 new). Ratchet 226.buildexit 0./api/voteand/api/emailboth load in a production server.Found along the way, deliberately not fixed
Every IPv4-mapped address (
::ffff:a.b.c.d) hashes like::1, because zeroing the last four IPv6 groups erases the embedded IPv4 address. This is probably not reachable in production: Vercel overwritesx-forwarded-forwith the public client IP, and the::ffff:form only comes from the localremoteAddressfallback. Fixing it changes those hashes, so it stays out of a move that had to keep every hash identical. It is recorded in the plan's backlog.🤖 Generated with Claude Code
https://claude.ai/code/session_01RE7Gq8fzzVAfBahzvcUqTP