Some checks failed
Go Benchmark / Performance Regression Check (push) Has been cancelled
Cerberus Integration / Cerberus Security Stack Integration (push) Has been cancelled
Upload Coverage to Codecov / Backend Codecov Upload (push) Has been cancelled
Upload Coverage to Codecov / Frontend Codecov Upload (push) Has been cancelled
CodeQL - Analyze / CodeQL analysis (go) (push) Has been cancelled
CodeQL - Analyze / CodeQL analysis (javascript-typescript) (push) Has been cancelled
CrowdSec Integration / CrowdSec Bouncer Integration (push) Has been cancelled
Docker Build, Publish & Test / build-and-push (push) Has been cancelled
Quality Checks / Auth Route Protection Contract (push) Has been cancelled
Quality Checks / Codecov Trigger/Comment Parity Guard (push) Has been cancelled
Quality Checks / Backend (Go) (push) Has been cancelled
Quality Checks / Frontend (React) (push) Has been cancelled
Rate Limit integration / Rate Limiting Integration (push) Has been cancelled
Security Scan (PR) / Trivy Binary Scan (push) Has been cancelled
Supply Chain Verification (PR) / Verify Supply Chain (push) Has been cancelled
WAF integration / Coraza WAF Integration (push) Has been cancelled
Docker Build, Publish & Test / Security Scan PR Image (push) Has been cancelled
Repo Health Check / Repo health (push) Has been cancelled
History Rewrite Dry-Run / Dry-run preview for history rewrite (push) Has been cancelled
Prune Renovate Branches / prune (push) Has been cancelled
Renovate / renovate (push) Has been cancelled
Nightly Build & Package / sync-development-to-nightly (push) Has been cancelled
Nightly Build & Package / Trigger Nightly Validation Workflows (push) Has been cancelled
Nightly Build & Package / build-and-push-nightly (push) Has been cancelled
Nightly Build & Package / test-nightly-image (push) Has been cancelled
Nightly Build & Package / verify-nightly-supply-chain (push) Has been cancelled
63 lines
1.5 KiB
Go
Executable File
63 lines
1.5 KiB
Go
Executable File
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/Wikid82/charon/backend/internal/util"
|
|
)
|
|
|
|
// SanitizeHeaders returns a map of header keys to redacted/sanitized values
|
|
// for safe logging. Sensitive headers are redacted; other values are
|
|
// sanitized using util.SanitizeForLog and truncated.
|
|
func SanitizeHeaders(h http.Header) map[string][]string {
|
|
if h == nil {
|
|
return nil
|
|
}
|
|
sensitive := map[string]struct{}{
|
|
"authorization": {},
|
|
"cookie": {},
|
|
"set-cookie": {},
|
|
"proxy-authorization": {},
|
|
"x-api-key": {},
|
|
"x-api-token": {},
|
|
"x-access-token": {},
|
|
"x-auth-token": {},
|
|
"x-api-secret": {},
|
|
"x-forwarded-for": {},
|
|
}
|
|
out := make(map[string][]string, len(h))
|
|
for k, vals := range h {
|
|
keyLower := strings.ToLower(k)
|
|
if _, ok := sensitive[keyLower]; ok {
|
|
out[k] = []string{"<redacted>"}
|
|
continue
|
|
}
|
|
sanitizedVals := make([]string, 0, len(vals))
|
|
for _, v := range vals {
|
|
v2 := util.SanitizeForLog(v)
|
|
if len(v2) > 200 {
|
|
v2 = v2[:200]
|
|
}
|
|
sanitizedVals = append(sanitizedVals, v2)
|
|
}
|
|
out[k] = sanitizedVals
|
|
}
|
|
return out
|
|
}
|
|
|
|
// SanitizePath prepares a request path for safe logging by removing
|
|
// control characters and truncating long values. It does not include
|
|
// query parameters.
|
|
func SanitizePath(p string) string {
|
|
// remove query string
|
|
if i := strings.Index(p, "?"); i != -1 {
|
|
p = p[:i]
|
|
}
|
|
p = util.SanitizeForLog(p)
|
|
if len(p) > 200 {
|
|
p = p[:200]
|
|
}
|
|
return p
|
|
}
|