refactor(hash): dedupe edit-token hashing into shared helper - #80
Open
waterlemonnn wants to merge 1 commit into
Open
refactor(hash): dedupe edit-token hashing into shared helper#80waterlemonnn wants to merge 1 commit into
waterlemonnn wants to merge 1 commit into
Conversation
Six files each reimplemented SHA-256 edit-token hashing inline or as a local hashToken()/getTokenHash() helper. Add hashEditToken() to lib/utils/hash.ts (same algorithm, output stays byte-identical since existing posts.edit_token_hash rows depend on it) and switch all six call sites to import it instead.
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.
Closes #31.
Edit tokens were hashed with an inline
createHash("sha256").update(token).digest("hex")in six separate places (three localhashToken/getTokenHashhelpers, three fully inline). AddedhashEditToken()tolib/utils/hash.ts, alongside the existinghashIp/getClientIp, and pointed all six call sites at it:app/api/posts/route.tsapp/api/status/[token]/route.tsapp/api/edit/[token]/route.tsapp/api/posts/edit/[token]/route.tsapp/api/admin/posts/[id]/resend-token/route.tsapp/edit/[token]/page.tsxAlgorithm is unchanged — same
sha256(token)hex digest as before, so existingposts.edit_token_hashrows still resolve.randomBytestoken generation inroute.ts/resend-token/route.tswas left alone per the issue.Added a test in
lib/utils/hash.test.ts(determinism + a fixed known digest) copying the shape of the existinghashIp/getClientIptests.app/api/posts/route.test.tsmocks@/lib/utils/hashwith an explicit object instead ofimportOriginal, so it needed ahashEditTokenmock added too — otherwise the route's new import throws inside the mocked module.Verify