{"record":{"id":"bd8f654dec9070fb","repo":"crowdsecurity/crowdsec","slug":"while-creating-temp-file-w","errorCode":null,"errorMessage":"while creating temp file: %w","messagePattern":"while creating temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/appsec/request.go","lineNumber":272,"sourceCode":"\t\tlen(r.HeadersNameFilters) == 0 &&\n\t\tlen(r.ArgsContentFilters) == 0 &&\n\t\tlen(r.ArgsNameFilters) == 0 &&\n\t\t!r.BodyDrop && !r.HeadersDrop && !r.ArgsDrop {\n\t\tlog.Warningf(\"no filters, returning original request\")\n\t\treturn r.req\n\t}\n\n\tr2 := ParsedRequest{}\n\tr.FilterHeaders(&r2)\n\tr.FilterBody(&r2)\n\tr.FilterArgs(&r2)\n\treturn &r2\n}\n\nfunc (r *ReqDumpFilter) ToJSON() error {\n\tfd, err := os.CreateTemp(\"\", \"crowdsec_req_dump_*.json\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while creating temp file: %w\", err)\n\t}\n\tdefer fd.Close()\n\tenc := json.NewEncoder(fd)\n\tenc.SetIndent(\"\", \"  \")\n\n\treq := r.GetFilteredRequest()\n\n\tlog.Tracef(\"dumping : %+v\", req)\n\n\tif err := enc.Encode(req); err != nil {\n\t\t//Don't clobber the temp directory with empty files\n\t\terr2 := os.Remove(fd.Name())\n\t\tif err2 != nil {\n\t\t\tlog.Errorf(\"while removing temp file %s: %s\", fd.Name(), err)\n\t\t}\n\t\treturn fmt.Errorf(\"while encoding request: %w\", err)\n\t}\n\tlog.Infof(\"request dumped to %s\", fd.Name())","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/appsec/request.go#L254-L290","documentation":"Creating the temporary file for a request-dump JSON write (os.CreateTemp with prefix crowdsec_req_dump_*.json) failed in ReqDumpFilter.ToJSON. Typical causes: full /tmp, no permission, or exhausted file descriptors; the dump of the filtered request cannot be written.","triggerScenarios":"Calling ToJSON when os.CreateTemp(\"\", \"crowdsec_req_dump_*.json\") fails — read-only or full temp filesystem, wrong TMPDIR, or permission problems on the temp directory.","commonSituations":"Containers running with a read-only root filesystem or no writable /tmp, TMPDIR pointing to a non-existent path, disk full, or hardened runtimes blocking file creation.","solutions":["Check TMPDIR is set to an existing writable directory, or fix it","Ensure the temp filesystem is writable and has free space (df -h /tmp)","Run the container with a writable tmpfs mount (e.g. --tmpfs /tmp)","Inspect process permissions / SELinux or AppArmor denials for the temp dir"],"exampleFix":"// before\nTMPDIR=/nonexistent crowdsec ...\n// after\nTMPDIR=/var/tmp crowdsec ...   # /var/tmp writable","handlingStrategy":"try-catch","validationCode":"// check temp dir is writable before dumping\nif f, err := os.CreateTemp(\"\", \"probe_*\"); err == nil { f.Close(); os.Remove(f.Name()) } else { return err }","typeGuard":null,"tryCatchPattern":"if err := dump.ToJSON(); err != nil {\n    log.Errorf(\"request dump failed: %v\", err)\n    // continue serving, dump is best-effort\n}","preventionTips":["Ensure /tmp (or TMPDIR) is writable in containers (tmpfs mount)","Monitor disk space on the temp filesystem","Never run with a fully read-only rootfs if dumps are enabled"],"tags":["filesystem","io","debug","temp-file"],"backgroundTag":"file-open-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}