{"record":{"id":"f668b701f87f59b6","repo":"valyala/fasthttp","slug":"no-create-file-permissions","errorCode":null,"errorMessage":"no 'create file' permissions","messagePattern":"no 'create file' permissions","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"fs.go","lineNumber":1565,"sourceCode":"\t\t\t\t\"Allow write access to the directory with this file in order to improve fasthttp performance\", indexFilePath)\n\t\t\tmustCompress = false\n\t\t\treturn h.openFSFile(indexFilePath, mustCompress, fileEncoding)\n\t\t}\n\t\tif !errors.Is(err, fs.ErrNotExist) {\n\t\t\treturn nil, fmt.Errorf(\"cannot open file %q: %w\", indexFilePath, err)\n\t\t}\n\t}\n\n\tif !h.generateIndexPages {\n\t\treturn nil, fmt.Errorf(\"cannot access directory without index page: directory %q\", dirPath)\n\t}\n\n\treturn h.createDirIndex(ctx, dirPath, mustCompress, fileEncoding)\n}\n\nvar (\n\terrDirIndexRequired   = errors.New(\"directory index required\")\n\terrNoCreatePermission = errors.New(\"no 'create file' permissions\")\n)\n\nfunc (h *fsHandler) createDirIndex(ctx *RequestCtx, dirPath string, mustCompress bool, fileEncoding string) (*fsFile, error) {\n\tw := &bytebufferpool.ByteBuffer{}\n\n\tbase := ctx.URI()\n\n\t// io/fs doesn't support ReadDir with empty path.\n\tif dirPath == \"\" {\n\t\tdirPath = \".\"\n\t}\n\n\tbasePathEscaped := html.EscapeString(string(base.Path()))\n\t_, _ = fmt.Fprintf(w, \"<html><head><title>%s</title><style>.dir { font-weight: bold }</style></head><body>\", basePathEscaped)\n\t_, _ = fmt.Fprintf(w, \"<h1>%s</h1>\", basePathEscaped)\n\t_, _ = fmt.Fprintf(w, \"<ul>\")\n\n\tif len(basePathEscaped) > 1 {","sourceCodeStart":1547,"sourceCodeEnd":1583,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/fs.go#L1547-L1583","documentation":"errNoCreatePermission indicates the handler is not permitted to create files — specifically the auto-generated directory index — because CreateIndexPages (or equivalent permission) is disabled. fasthttp refuses to write generated content to disk in this configuration.","triggerScenarios":"A directory request requires building/caching a directory index, but the fsHandler is configured without permission to create the index file (index generation disabled), so this sentinel is returned.","commonSituations":"Production configs with GenerateIndexPages=false where clients request bare directory URLs; deploying read-only static servers and expecting listings; typos in IndexNames leaving no index file to serve.","solutions":["Enable index generation (fasthttp.Fs.GenerateIndexPages = true) if listings are desired","Provide a static index file and register it via IndexNames so no generation is needed","Disable directory browsing intentionally and return 403/404 for directory URLs by handling the error yourself","Serve an explicit file path instead of a directory"],"exampleFix":"// before\nfsHandler := h.fs.NewRequestHandler() // GenerateIndexPages=false, dir request -> refusal\n// after\nh.fs.GenerateIndexPages = true\n// or: h.fs.IndexNames = []string{\"index.html\"}","handlingStrategy":"validation","validationCode":"if !h.fs.GenerateIndexPages && len(h.fs.IndexNames) == 0 {\n    // directory requests will be refused; register an index or enable generation\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"create file\") {\n    ctx.Error(\"directory listing not available\", fasthttp.StatusForbidden)\n}","preventionTips":["Enable GenerateIndexPages only on writable, trusted roots","Prefer static index files over on-the-fly generation in production","Decide explicitly whether directory browsing is allowed and encode it in config","Check filesystem write permissions for the fasthttp process when generation is on"],"tags":["go","fasthttp","filesystem","permissions"],"backgroundTag":"directory-index-not-permitted","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}