{"record":{"id":"45d4397bbeefabef","repo":"JuliusBrussee/caveman","slug":"awssig-request-has-no-url","errorCode":null,"errorMessage":"awssig: request has no URL","messagePattern":"awssig: request has no URL","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/awssig/awssig.go","lineNumber":74,"sourceCode":"// the Authorization, X-Amz-Date, X-Amz-Content-Sha256 (and, when present,\n// X-Amz-Security-Token) headers on req. The Host header is derived from req.URL.\n//\n// payloadHash is the lowercase hex SHA-256 of the request body; pass\n// HashPayload(body) for the common case, or UnsignedPayload() for streaming\n// bodies that must not be buffered. now fixes the signing instant (use\n// time.Now().UTC()); it is a parameter so tests are deterministic.\n//\n// Sign returns an error only for malformed inputs (no region/service, missing\n// credentials, unparseable URL). It never returns the secret in the error.\nfunc (s Signer) Sign(req *http.Request, creds Credentials, payloadHash string, now time.Time) error {\n\tif s.Region == \"\" || s.Service == \"\" {\n\t\treturn fmt.Errorf(\"awssig: signer requires region and service\")\n\t}\n\tif !creds.Valid() {\n\t\treturn fmt.Errorf(\"awssig: incomplete AWS credentials\")\n\t}\n\tif req.URL == nil {\n\t\treturn fmt.Errorf(\"awssig: request has no URL\")\n\t}\n\tnow = now.UTC()\n\tamzDate := now.Format(\"20060102T150405Z\")\n\tdateStamp := now.Format(\"20060102\")\n\n\thost := req.URL.Host\n\tif req.Host != \"\" {\n\t\thost = req.Host\n\t}\n\treq.Header.Set(\"Host\", host)\n\treq.Header.Set(\"X-Amz-Date\", amzDate)\n\treq.Header.Set(\"X-Amz-Content-Sha256\", payloadHash)\n\tif creds.SessionToken != \"\" {\n\t\treq.Header.Set(\"X-Amz-Security-Token\", creds.SessionToken)\n\t}\n\n\tcanonicalHeaders, signedHeaders := canonicalHeaderSet(req, host)\n\tcanonicalRequest := strings.Join([]string{","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/awssig/awssig.go#L56-L92","documentation":"Signer.Sign requires req.URL to be non-nil to derive the host and canonical request; if the *http.Request was built without a URL (e.g. manually constructed rather than via http.NewRequest), signing fails with this error. It is a malformed-input guard on the request object itself.","triggerScenarios":"Calling Sign with an &http.Request{} literal (URL nil) instead of one built by http.NewRequest; a request whose URL was cleared/replaced with nil before signing.","commonSituations":"Hand-assembling http.Request in tests or middleware; a code path that parses a URL conditionally and leaves it nil on some branches; passing a server-side received request after stripping fields.","solutions":["Build the request with http.NewRequest(http.MethodGet, rawURL, body) so URL and Host are populated.","Before signing, assert req.URL != nil && req.URL.Host != \"\" and fail with a clear message.","If the URL is assigned dynamically, ensure the assignment happens before Sign is called."],"exampleFix":"// before\nreq := &http.Request{Method: \"GET\", Header: h}\n// after\nreq, err := http.NewRequest(http.MethodGet, \"https://s3.us-east-1.amazonaws.com/bucket/key\", nil)\nif err != nil { return err }\nerr = signer.Sign(req, creds, payloadHash, now)","handlingStrategy":"validation","validationCode":"func signable(req *http.Request) bool { return req != nil && req.URL != nil && req.URL.Host != \"\" }\nif !signable(req) {\n    return errors.New(\"request must be built via http.NewRequest with a full URL before signing\")\n}","typeGuard":null,"tryCatchPattern":"if err := signer.Sign(req, creds, hash, now); err != nil {\n    if strings.Contains(err.Error(), \"request has no URL\") {\n        return fmt.Errorf(\"request construction bug: %w\", err)\n    }\n    return err\n}","preventionTips":["Always create outbound requests with http.NewRequest/NewRequestWithContext, not struct literals.","Assign the URL before any signing middleware runs.","Add a test asserting every signed request has req.URL != nil."],"tags":["aws","sigv4","http-request","signing"],"backgroundTag":"invalid-url","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}