-
Notifications
You must be signed in to change notification settings - Fork 887
feat: disable directory listings for static files #12229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Static file server handles serving static asset files (js, css, etc). The default file server would also list all files in a directory. This has been changed to only serve files.
@@ -129,7 +130,15 @@ func New(opts *Options) *Handler { | |||
// If-Match and If-None-Match headers on the request properly. | |||
http.FileServer(opts.BinFS).ServeHTTP(rw, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Binary directory
// Serve the directory listing. | ||
// Serve the directory listing. This intentionally allows directory listings to | ||
// be served. This file system should not contain anything sensitive. | ||
http.FileServer(opts.BinFS).ServeHTTP(rw, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
// Serve the directory listing. | ||
// Serve the directory listing. This intentionally allows directory listings to | ||
// be served. This file system should not contain anything sensitive. | ||
http.FileServer(opts.BinFS).ServeHTTP(rw, r) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
func FS() fs.FS { | ||
return slim | ||
// This is required to contain an index.html file for unit tests. | ||
// Our unit tests frequently just hit `/` and expect to get a 200. | ||
// So a valid index.html file should be expected to be served. | ||
return fstest.MapFS{ | ||
"index.html": &fstest.MapFile{ | ||
Data: []byte("Slim build of Coder, does not contain the frontend static files."), | ||
ModTime: time.Now(), | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kylecarbs I had to add this so unit tests work. When they query /
it was a 404 since /
was a directory, which now is not allowed.
Static file server handles serving static asset files (js, css, etc). The default file server would also list all files in a directory. This has been changed to only serve files.
Now directories return a 404
Closes #12235