update readme and build

This commit is contained in:
2026-05-24 07:18:54 +00:00
parent 45e18b5423
commit 5b4803bc49
9 changed files with 447 additions and 38 deletions
+38
View File
@@ -11,6 +11,44 @@ import (
"time"
)
// ── CSRF ──────────────────────────────────────────────────────────────
func newCSRFToken() string {
b := make([]byte, 24)
rand.Read(b) //nolint:errcheck
return hex.EncodeToString(b)
}
// setCSRFCookie writes a fresh CSRF token to a short-lived cookie and returns
// the token value so it can be embedded in the rendered HTML form.
func setCSRFCookie(w http.ResponseWriter) string {
tok := newCSRFToken()
http.SetCookie(w, &http.Cookie{
Name: csrfCookieName,
Value: tok,
Path: "/",
HttpOnly: true,
Secure: true,
SameSite: http.SameSiteStrictMode,
MaxAge: 900, // 15 min — covers slow typists
})
return tok
}
// checkCSRF returns true iff the submitted csrf_token form field matches the
// cookie value (constant-time compare to prevent timing side-channels).
func checkCSRF(r *http.Request) bool {
c, err := r.Cookie(csrfCookieName)
if err != nil || c.Value == "" {
return false
}
formTok := r.FormValue("csrf_token")
if formTok == "" {
return false
}
return hmac.Equal([]byte(c.Value), []byte(formTok))
}
func checkCreds(username, password string) bool {
if username != appCreds.Username {
return false