Repository navigation
Spam and phishing protection, API keys for shortening links - #42
Merged
Merged
Conversation
… behind keys The database holds phishing links (fake login and update pages such as iaccess-update-login.org.nz and vinted.verificationpage.sbs) and product spam. The abuse filter against other shorteners and own links was never called, and the client address came from CF-Connecting-IP or the first X-Forwarded-For entry, both set by the client. - The client address is X-Real-IP (set by Apache) or the last X-Forwarded-For entry, never a header the client chooses. - The target check now runs: no own links, no other shorteners, no IP hosts, and no hostnames built like phishing pages (several bait words, or one with a cheap TLD, many hyphens or punycode). - The form needs a solved Cloudflare Turnstile (required in production, fails closed), the same origin, an untouched honeypot and a signed form stamp at least two seconds old. Per address it may shorten 20 links a day, counted in the database. - Scripts need an API key. scripts/api-key.sh (help, list, create, revoke, delete) manages them on the server; only the SHA-256 is stored. - The privacy policy names Turnstile, the README the key requirement. - Vitest for the rules; the build workflow now type-checks and tests too.
Dependency ReviewThe following issues were found:
OpenSSF ScorecardScorecard details
Scanned Files
|
This was referenced Oct 30, 2026
CodeQL flagged the SHA-256 of an API key as an insufficient password hash. Keys are 32 random bytes, but scrypt is the password-grade choice and keeps a leaked table useless even against a weaker key. Hashing now costs a few milliseconds, so it is bounded: a key without the exact format (msks_ and 43 base64url characters) is turned down before hashing, and an address is stopped for ten minutes after ten wrong keys. The hash runs off the main thread.
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.
Why
The database holds phishing links, fake login and update pages such as
iaccess-update-login.org.nz,lbpiaccess-mobile-login.infoandvinted.verificationpage.sbs, plus product spam.Two gaps made that easy:
src/lib/abuseFilter.ts(other shorteners, own links) was never called.CF-Connecting-IPor the firstX-Forwarded-Forentry, both set by the client, so the per-address limit could be walked around.What
Client address.
X-Real-IP(Apache sets it from the connection) or the lastX-Forwarded-Forentry. Never a header the client chooses.Target checks, now wired in for every request:
accounts.google.comandlogin.microsoftonline.compass.The form, in order of cost:
Scripts need an API key (
Authorization: Bearer msks_…). Without a key the API answers 401. Keys are managed withscripts/api-key.sh(help,list,create,revoke,delete), only the SHA-256 is stored (migration005_api_keys.sql).Privacy policy, README and
.env.exampleare updated. Vitest covers the rules, and the build workflow now type-checks and tests too.Before merging
The server's
/opt/msk-shortener/.envneedsCAPTCHA_SITE_KEYandCAPTCHA_SECRET_KEYfrom a Turnstile widget fors.msk-scripts.de. Without them the form refuses to shorten in production.Checked