Make CORS handling configurable

Signed-off-by: Quincy Mast <email.quincymast@gmail.com>
This commit is contained in:
Quincy Mast 2024-12-31 10:58:43 -05:00
parent 1b29e6ae8f
commit 1e3d10c1ae
2 changed files with 9 additions and 5 deletions

3
api.go
View file

@ -56,6 +56,7 @@ func (a apiServer) Register(r *mux.Router) {
} }
func (a apiServer) handleCreate(res http.ResponseWriter, r *http.Request) { func (a apiServer) handleCreate(res http.ResponseWriter, r *http.Request) {
if cust.AddCORSHeaders {
res.Header().Set("Access-Control-Allow-Origin", "*") res.Header().Set("Access-Control-Allow-Origin", "*")
res.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS") res.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
if r.Method == http.MethodOptions { if r.Method == http.MethodOptions {
@ -63,6 +64,8 @@ func (a apiServer) handleCreate(res http.ResponseWriter, r *http.Request) {
return return
} }
}
if cust.MaxSecretSize > 0 { if cust.MaxSecretSize > 0 {
// As a safeguard against HUGE payloads behind a misconfigured // As a safeguard against HUGE payloads behind a misconfigured
// proxy we take double the maximum secret size after which we // proxy we take double the maximum secret size after which we

View file

@ -41,6 +41,7 @@ type (
MetricsAllowedSubnets []string `json:"-" yaml:"metricsAllowedSubnets"` MetricsAllowedSubnets []string `json:"-" yaml:"metricsAllowedSubnets"`
OverlayFSPath string `json:"-" yaml:"overlayFSPath"` OverlayFSPath string `json:"-" yaml:"overlayFSPath"`
UseFormalLanguage bool `json:"-" yaml:"useFormalLanguage"` UseFormalLanguage bool `json:"-" yaml:"useFormalLanguage"`
AddCORSHeaders bool `json:"-" yaml:"addCORSHeaders"`
FooterLinks []FooterLink `json:"footerLinks,omitempty" yaml:"footerLinks"` FooterLinks []FooterLink `json:"footerLinks,omitempty" yaml:"footerLinks"`
} }