{"record":{"id":"c3d7c801273db51a","repo":"siyuan-note/siyuan","slug":"invalid-request","errorCode":null,"errorMessage":"invalid request: ","messagePattern":"invalid request: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/httprequest.go","lineNumber":327,"sourceCode":"\t\treturn 0, \"\", \"\", errors.New(\"URL has no host\")\n\t}\n\n\tif serr := CheckHostSSRF(u.Hostname()); serr != nil {\n\t\treturn 0, \"\", \"\", serr\n\t}\n\n\tmethod = strings.ToUpper(strings.TrimSpace(method))\n\tif method == \"\" {\n\t\tmethod = \"GET\"\n\t}\n\n\tvar reqBody io.Reader\n\tif body != \"\" && method != \"GET\" && method != \"HEAD\" {\n\t\treqBody = strings.NewReader(body)\n\t}\n\treq, err := http.NewRequest(method, rawURL, reqBody)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"invalid request: \" + err.Error())\n\t}\n\tfor k, v := range headers {\n\t\treq.Header.Set(k, v)\n\t}\n\n\tresp, err := ssrfSafeClient.Do(req)\n\tif err != nil {\n\t\treturn 0, \"\", \"\", errors.New(\"request failed: \" + err.Error())\n\t}\n\tif resp == nil {\n\t\treturn 0, \"\", \"\", errors.New(\"nil response\")\n\t}\n\tdefer resp.Body.Close()\n\n\tstatusCode = resp.StatusCode\n\tcontentType = resp.Header.Get(\"Content-Type\")\n\n\tmaxReadBytes := int64(maxHTTPRequestBytes)","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/httprequest.go#L309-L345","documentation":"HTTPRequest builds the actual *http.Request with http.NewRequest after normalizing the method. If that constructor rejects the input (unsupported method token containing invalid characters, unparseable URL at request level, malformed context URL), the error is wrapped as \"invalid request: <detail>\".","triggerScenarios":"Calling HTTPRequest with a method string containing invalid HTTP token characters (e.g. \"GET /extra\", \"FETCH DATA\", method with spaces or non-ASCII) or a URL that url.Parse accepted earlier but http.NewRequest rejects (rare malformed forms).","commonSituations":"Agent/LLM inventing non-standard HTTP verbs; method strings with trailing whitespace already trimmed but embedded spaces remaining; passing a full request line instead of just the verb; Go version differences in URL validation.","solutions":["Use one of GET/POST/PUT/DELETE/PATCH (or another standard verb) with no extra characters","Inspect the wrapped detail after \"invalid request: \" to see whether the method or the URL was rejected","Sanitize the method: strings.ToUpper(strings.TrimSpace(method)) and reject strings containing spaces","Validate the URL with http.NewRequest(method, url, nil) in a dry run before the real call"],"exampleFix":"// before\nHTTPRequest(\"GET /v1/data\", \"https://api.example.com\", nil, \"\")\n// after\nHTTPRequest(\"GET\", \"https://api.example.com/v1/data\", nil, \"\")","handlingStrategy":"validation","validationCode":"method = strings.ToUpper(strings.TrimSpace(method))\nif strings.ContainsAny(method, \" \\t/\") {\n    return fmt.Errorf(\"method %q is not a valid HTTP token\", method)\n}","typeGuard":"func isValidHTTPMethod(m string) bool {\n    switch strings.ToUpper(strings.TrimSpace(m)) {\n    case \"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"HEAD\", \"OPTIONS\":\n        return true\n    }\n    return false\n}","tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"invalid request: \") {\n    detail := strings.TrimPrefix(err.Error(), \"invalid request: \")\n    return fmt.Errorf(\"check method/URL inputs: %s\", detail)\n}","preventionTips":["Pass only standard HTTP verbs, free of spaces or extra tokens","Normalize and validate the method string before calling HTTPRequest","Constrain LLM-generated tool arguments to an enum of allowed verbs"],"tags":["http","validation","invalid-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}