Quellcode durchsuchen

Set Content-Type on provisioner webhook requests

Provisioner webhook requests POST a JSON body, but never set a
Content-Type header. http.NewRequestWithContext populates
ContentLength from the *bytes.Reader body and nothing else, and Go's
HTTP client does not infer a content type, so the request went out
with the body unlabelled.

Webhook servers that dispatch on Content-Type reject these requests.
Express's express.json() and Spring's @RequestBody both require
application/json and respond 400 or hand the handler an empty body.

Set the header alongside the other webhook headers. This covers every
webhook kind, since enriching, authorizing and the SCEP challenge and
notify webhooks all send through DoWithContext.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L76jtApP9cwBbYD3DVSuWW
Josh Drake vor 2 Monaten
Ursprung
Commit
0f4dcb0724
2 geänderte Dateien mit 4 neuen und 0 gelöschten Zeilen
  1. 2 0
      authority/provisioner/webhook.go
  2. 2 0
      authority/provisioner/webhook_test.go

+ 2 - 0
authority/provisioner/webhook.go

@@ -227,6 +227,8 @@ retry:
 		return nil, err
 	}
 
+	req.Header.Set("Content-Type", "application/json")
+
 	if requestID, ok := requestid.FromContext(ctx); ok {
 		req.Header.Set("X-Request-Id", requestID)
 	}

+ 2 - 0
authority/provisioner/webhook_test.go

@@ -567,6 +567,8 @@ func TestWebhook_Do(t *testing.T) {
 					assert.Equal(t, tc.requestID, r.Header.Get("X-Request-ID"))
 				}
 
+				assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
+
 				assert.Equal(t, tc.webhook.ID, r.Header.Get("X-Smallstep-Webhook-ID"))
 
 				sig, err := hex.DecodeString(r.Header.Get("X-Smallstep-Signature"))