Repository navigation
feat: metrics, votes, ALTCHA and rate limits - #5
Merged
Merged
Conversation
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.
Stage 5: metrics, votes, ALTCHA, rate limits,
/metrics.Changes
internal/store): SQLite atDATA_DIR/hyperhack.db(mode 0600, WAL) viamodernc.org/sqlitev1.61.0. Per-post counters, daily views for "Popular", votes keyed by the hashedvidcookie, and search stats. An hourly prune drops old search and daily rows.internal/ratelimit): per-client token bucket (IPv4 /32, IPv6 /64), LRU of 10k clients. 429 +Retry-Afteron/api/altcha,/api/vote,/api/beacon,/searchand/reindex. The WARN log carries the endpoint, never the IP.GET /api/altcha+POST /api/vote. Like / dislike / none, one vote pervidcookie (HttpOnly, SameSite=Lax, Secure on https). Each vote needs a solved ALTCHA challenge. Signatures cannot be replayed. Origin / Sec-Fetch-Site are checked on every API call.altcha-lib-go/v2v2.4.1 on the server, with our own small solver (static/altcha.js, Web Crypto) on the page. A test runs the embedded JS solver in node and checks its payload againstaltcha.VerifySolution(fast and re-derive paths) andaltcha.SolveChallenge.POST /api/beaconsends a delta on every hide. Each delta carries a random per-page-view id. The server sums time per view and clamps the sum at 4 h before it reaches the aggregate. Views, depth, source, device, lang and theme are counted once per visitor and post per day, using an in-memory HMAC visitor key with a daily key. Outbound clicks are counted only for hosts linked from the post. Code copies are counted too. Fuzz test included./metrics: Prometheus text format, CIDR-restricted byMETRICS_ALLOW. Exposes per-post counters, likes/dislikes gauges, sync stats, search counters and latency, top queries and top zero-result queries, and HTTP requests and latency per route.Checks
go vet,staticcheckv0.8.2,govulncheckv1.9.0, andgo test -race ./...all pass. govulncheck reports one x/crypto advisory (GO-2026-5932) that our code does not reach.FuzzBeaconran 45 s with no failures./metricsoutput looks right;Not checked
crypto.subtlethere, so the vote buttons stay disabled. Production is https.