{"record":{"id":"0a707f6f7bb90f48","repo":"ory/hydra","slug":"failed-to-parse-form-s","errorCode":null,"errorMessage":"Failed to parse form: %s","messagePattern":"Failed to parse form: (.+?)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"cmd/cmd_perform_device_flow.go","lineNumber":175,"sourceCode":"func (s *deviceSrv) GETdevice(w http.ResponseWriter, r *http.Request) {\n\tif r.URL.Query().Get(\"device_challenge\") == \"\" {\n\t\thttp.Error(w, \"device_challenge is required\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\terr := userCodeTemplate.Execute(w, userCodeData{\n\t\tUserCode:        r.URL.Query().Get(\"user_code\"),\n\t\tDeviceChallenge: r.URL.Query().Get(\"device_challenge\"),\n\t})\n\tif err != nil {\n\t\thttp.Error(w, fmt.Sprintf(\"Failed to render template: %s\", err), http.StatusInternalServerError)\n\t\treturn\n\t}\n}\n\nfunc (s *deviceSrv) POSTdevice(w http.ResponseWriter, r *http.Request) {\n\tif err := r.ParseForm(); err != nil {\n\t\thttp.Error(w, fmt.Sprintf(\"Failed to parse form: %s\", err), http.StatusBadRequest)\n\t\treturn\n\t}\n\tuserCode, challenge := r.FormValue(\"user_code\"), r.FormValue(\"device_challenge\")\n\tif userCode == \"\" {\n\t\thttp.Error(w, \"user_code is required\", http.StatusBadRequest)\n\t\treturn\n\t}\n\tif challenge == \"\" {\n\t\thttp.Error(w, \"device_challenge is required\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\t// Accept the user code with a hand-rolled request instead of the generated\n\t// client: other modules in this repository compile this package against the\n\t// released hydra-client-go/v2 module, which predates the device\n\t// authorization API.\n\tcfg := s.cl.GetConfig()\n\tif len(cfg.Servers) == 0 {","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/cmd/cmd_perform_device_flow.go#L157-L193","documentation":"POSTdevice parses the submitted form before reading the user code and device challenge. If r.ParseForm() fails (malformed body, unsupported content type), the handler responds 400 with 'Failed to parse form: <err>'.","triggerScenarios":"Submitting the device user-code form with a corrupted or non-urlencoded body, or a client POSTing JSON/multipart to this endpoint.","commonSituations":"Manual curl tests with wrong content type; browser extensions or proxies altering the form body; custom automation posting JSON instead of urlencoded fields.","solutions":["POST application/x-www-form-urlencoded fields user_code and device_challenge","Verify Content-Type header is application/x-www-form-urlencoded","Inspect the raw body for truncation or encoding issues","Test with the normal HTML form from the device page to confirm baseline behavior"],"exampleFix":"// before\ncurl -X POST http://localhost:4445/device -H 'Content-Type: application/json' -d '{\"user_code\":\"1234\"}'\n// after\ncurl -X POST http://localhost:4445/device -d 'user_code=1234&device_challenge=abc'","handlingStrategy":"validation","validationCode":"// client side\nrequests.post(url, data={\"user_code\": code, \"device_challenge\": ch},\n              headers={\"Content-Type\": \"application/x-www-form-urlencoded\"})","typeGuard":null,"tryCatchPattern":null,"preventionTips":["POST urlencoded forms, not JSON, to this endpoint","Set Content-Type: application/x-www-form-urlencoded","Keep bodies small and untruncated through proxies","Smoke-test the form with curl before automating it"],"tags":["http","form","device-flow","parsing"],"backgroundTag":"form-parse-failed","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}