Security features persistence#7
Open
mdhaiwat wants to merge 2 commits into
Open
Conversation
Security fixes:
- Per-IP POST rate limiting (30 req/min sliding window, ratelimit.go)
- HTTP Basic Auth on admin endpoint with constant-time SHA-256 compare
- TLS 1.2+ AEAD-only cipher suites (GCM + ChaCha20-Poly1305), X25519 first
- ReadTimeout/WriteTimeout/IdleTimeout on all HTTP servers
- Blocklist support (BlockedDomains config + optional BlocklistFile)
- All URL inputs validated; javascript: and other schemes rejected
- compress/decompress uses base64(gzip) to prevent JSON corruption of binary bytes
- Decompression bomb protection: 20 MiB cap via io.LimitReader
- lookupLink returns a snapshot copy (eliminates post-RLock field-read races)
- recordAccess decides Times consumption under the write lock (removes racy parameter)
- Add() snapshots Link before saveLinkToDB goroutine (prevents NextClear write race)
- Authoritative duplicate custom-key check inside Add() under write lock
- Salt and HashSHA256 redacted from startup log
- Correct HTTP status codes: 400 for invalid key, 404 for not-found, 403 for blocklist
New features:
- bbolt persistence (db.go rewrite): links survive restarts; prunes expired entries on boot
- JSON API: POST /api/v1/shorten, GET /api/v1/lookup/{key} (api.go)
- QR code endpoint: GET /qr/{key} returns 256x256 PNG (qr.go)
- Click analytics: AccessCount tracked per link, exposed via API
- URL deduplication: repeated submissions of same unlimited URL return existing key
- Security headers: X-Content-Type-Options, Referrer-Policy, optional HSTS/CSP/Report-To
Cleanup:
- Removed dead globals (TextBlobs, BackupLink* slices)
- validate() uses pre-built O(k) charset map instead of O(k*n) scan
- go/build replaced with os.UserHomeDir() in findFolderDefaultLocations
- getActiveList uses strings.Builder; shows <compressed> for compressed blobs
- Go version bumped to 1.23; dependencies: bbolt v1.4.3, go-qrcode
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
No description provided.