You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🔒 fix: audit setCORSHeaders callers to pass explicit methods (#8201)
Copilot review on merged PR #8198 flagged that setCORSHeaders still
defaults Access-Control-Allow-Methods to "GET, OPTIONS" unless callers
pass an explicit method list, and that several existing kc-agent
handlers serving POST/DELETE (e.g. /serviceaccounts) were still calling
setCORSHeaders(w, r) without methods, so their preflight responses
advertised only GET/OPTIONS and browsers rejected cross-origin
POST/DELETE.
This PR audits every setCORSHeaders caller in pkg/agent and updates the
non-GET handlers to pass an explicit method list. The default of
"GET, OPTIONS" is preserved for back-compat and remains correct for the
read-only handlers.
Handlers updated to advertise correct Allow-Methods on preflight:
server_http.go
- handleNamespacesHTTP GET, POST, DELETE, OPTIONS
- handleServiceAccountsHTTP GET, POST, DELETE, OPTIONS
- handleServiceExportsHTTP POST, DELETE, OPTIONS
- handleRoleBindingsHTTP GET, POST, DELETE, OPTIONS
- handleScaleHTTP POST, OPTIONS (consolidated from inline)
- handleDeployWorkloadHTTP POST, OPTIONS (consolidated from inline)
- handleDeleteWorkloadHTTP POST, OPTIONS (consolidated from inline)
- handleAutoUpdateConfig GET, POST, OPTIONS (was OPTIONS-only)
- handleAutoUpdateTrigger POST, OPTIONS (was OPTIONS-only)
- handleAutoUpdateCancel POST, OPTIONS (was OPTIONS-only)
- handleKubeconfigRemoveHTTP POST, OPTIONS (consolidated from inline)
server_helm.go
- handleHelmRollback POST, OPTIONS
- handleHelmUninstall POST, OPTIONS
- handleHelmUpgrade POST, OPTIONS
server_gitops.go
- handleDetectDrift POST, OPTIONS
- handleGitopsSync POST, OPTIONS
server_console_cr.go
- handleConsoleCRManagedWorkloads POST, PUT, DELETE, OPTIONS
- handleConsoleCRClusterGroups POST, PUT, DELETE, OPTIONS
- handleConsoleCRWorkloadDeployments POST, DELETE, OPTIONS
- handleConsoleCRWorkloadDeploymentStatus PUT, OPTIONS
server_argocd.go
- handleArgoCDSync POST, OPTIONS (consolidated from inline)
server_gpu_health.go
- handleGPUHealthCronJob POST, DELETE, OPTIONS
server_operations.go
- handleLocalClusters GET, POST, DELETE, OPTIONS
- handleLocalClusterLifecycle POST, OPTIONS
- handleVClusterCreate POST, OPTIONS
- handleVClusterConnect POST, OPTIONS
- handleVClusterDisconnect POST, OPTIONS
- handleVClusterDelete POST, OPTIONS
GET-only handlers (gpu-nodes, nodes, pods, events, deployments,
replicasets, statefulsets, daemonsets, cronjobs, ingresses, services,
configmaps, secrets, jobs, hpas, pvcs, roles, resourcequotas,
limitranges, resolvedeps, clusterhealth, autoupdatestatus, kagenti/*,
kagent-crds/*, prometheus query, vCluster list/check, cloudCLIStatus,
localClusterTools, rbac/permissions, permissions/summary) keep the
default and remain correct.
Also updates the setCORSHeaders doc comment with an explicit audit rule
so future handlers serving non-GET methods don't silently regress.
Adds a regression test (TestHandleServiceAccounts_CORSMethodsHeader)
that pins the fix on the specific handler Copilot called out.
Fixes#8201
Signed-off-by: Andy Anderson <[email protected]>
0 commit comments