Skip to content

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

Merged
merged 9 commits into from
Feb 20, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Feb 20, 2024

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

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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binary directory

Comment on lines -105 to 107
// 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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels beneficial to keep this for listing what binaries are supported. Thoughts?

Screenshot from 2024-02-20 09-37-57

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it!

@Emyrk Emyrk marked this pull request as draft February 20, 2024 15:45
Comment on lines -105 to 107
// 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it!

@Emyrk Emyrk marked this pull request as ready for review February 20, 2024 19:42
Comment on lines 12 to 22
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(),
},
}
}
Copy link
Member Author

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.

@Emyrk Emyrk requested a review from kylecarbs February 20, 2024 19:43
@Emyrk Emyrk merged commit 07cccf9 into main Feb 20, 2024
@Emyrk Emyrk deleted the stevenmasley/no_serve_dirs branch February 20, 2024 21:50
@github-actions github-actions bot locked and limited conversation to collaborators Feb 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

disable directory support
2 participants