- Backend: - Fix ListTickets parameter order mismatch for assignee filtering - Replicate all 13 PostgreSQL tables and columns during disaster recovery sync and rollback - Implement server-side session store with HttpOnly cookies and Bearer tokens - Add profile update verification requiring current password - Whitelist allowed file uploads and apply strict security headers (nosniff, CSP) - Enforce role check on error deletion (admin/lead/tester only) and authenticate SSE stream - Align foreign key user_id for saved filters and api tokens - Add ReopenTicket endpoint and workflow - Integrate Cloudflare Turnstile verification with testing/production key support - Frontend: - Remove liquid glass displacement filter and lens capsule for high-performance UI - Eliminate recursive backdrop-filters and heavy inset shadows - Add debounced search and optimize SSE re-rendering - Wire Saved Views filter bar with creation, active indicators, and deletion - Add Linked & Related Tickets management UI to sheet - Seed 6 demo personas in PostgreSQL with instant sign-in - Add Cloudflare Turnstile widgets to authentication modals - Add keyboard arrow navigation to Command Palette - Image Manipulator, Docs & Tooling: - Sync image manipulator updates, docs, and test coordinates
90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package khira
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
DefaultTurnstileSiteKey = "1x00000000000000000000AA"
|
|
DefaultTurnstileSecretKey = "1x0000000000000000000000000000000AA"
|
|
TurnstileVerifyEndpoint = "https://challenges.cloudflare.com/turnstile/v0/siteverify"
|
|
)
|
|
|
|
type TurnstileClient struct {
|
|
SiteKey string
|
|
SecretKey string
|
|
httpClient *http.Client
|
|
}
|
|
|
|
type TurnstileResponse struct {
|
|
Success bool `json:"success"`
|
|
ChallengeTS time.Time `json:"challenge_ts"`
|
|
Hostname string `json:"hostname"`
|
|
ErrorCodes []string `json:"error-codes"`
|
|
Action string `json:"action"`
|
|
CData string `json:"cdata"`
|
|
}
|
|
|
|
func NewTurnstileClient() *TurnstileClient {
|
|
siteKey := os.Getenv("KHIRA_TURNSTILE_SITE_KEY")
|
|
if strings.TrimSpace(siteKey) == "" {
|
|
siteKey = DefaultTurnstileSiteKey
|
|
}
|
|
secretKey := os.Getenv("KHIRA_TURNSTILE_SECRET_KEY")
|
|
if strings.TrimSpace(secretKey) == "" {
|
|
secretKey = DefaultTurnstileSecretKey
|
|
}
|
|
|
|
return &TurnstileClient{
|
|
SiteKey: siteKey,
|
|
SecretKey: secretKey,
|
|
httpClient: &http.Client{
|
|
Timeout: 10 * time.Second,
|
|
},
|
|
}
|
|
}
|
|
|
|
// Verify verifies a turnstile challenge token against Cloudflare's siteverify endpoint.
|
|
func (tc *TurnstileClient) Verify(token, remoteIP string) (bool, error) {
|
|
token = strings.TrimSpace(token)
|
|
if token == "" {
|
|
return false, fmt.Errorf("empty turnstile token")
|
|
}
|
|
|
|
form := url.Values{}
|
|
form.Set("secret", tc.SecretKey)
|
|
form.Set("response", token)
|
|
if remoteIP != "" {
|
|
form.Set("remoteip", remoteIP)
|
|
}
|
|
|
|
req, err := http.NewRequest("POST", TurnstileVerifyEndpoint, strings.NewReader(form.Encode()))
|
|
if err != nil {
|
|
return false, fmt.Errorf("failed to create turnstile request: %w", err)
|
|
}
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
resp, err := tc.httpClient.Do(req)
|
|
if err != nil {
|
|
return false, fmt.Errorf("failed to contact turnstile verification server: %w", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
return false, fmt.Errorf("turnstile verification returned status %d", resp.StatusCode)
|
|
}
|
|
|
|
var res TurnstileResponse
|
|
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
|
|
return false, fmt.Errorf("failed to decode turnstile verification response: %w", err)
|
|
}
|
|
|
|
return res.Success, nil
|
|
}
|