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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Swagger default to 404
  • Loading branch information
Emyrk committed Feb 20, 2024
commit f76b6bf2cf3064130c6dbf98e9daa4ea71a25d0c
3 changes: 3 additions & 0 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,9 @@ func New(options *Options) *API {
// See globalHTTPSwaggerHandler comment as to why we use a package
// global variable here.
r.Get("/swagger/*", globalHTTPSwaggerHandler)
} else {
r.Get("/swagger", http.NotFound)
r.Get("/swagger/*", http.NotFound)
}

// Add CSP headers to all static assets and pages. CSP headers only affect
Expand Down
10 changes: 2 additions & 8 deletions coderd/coderd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,9 @@ func TestSwagger(t *testing.T) {

resp, err := requestWithRetries(ctx, t, client, http.MethodGet, swaggerEndpoint, nil)
require.NoError(t, err)

body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
defer resp.Body.Close()

require.Contains(t, string(body), "Slim build of Coder")
require.Equal(t, http.StatusNotFound, resp.StatusCode)
})
t.Run("doc.json disabled by default", func(t *testing.T) {
t.Parallel()
Expand All @@ -329,12 +326,9 @@ func TestSwagger(t *testing.T) {

resp, err := requestWithRetries(ctx, t, client, http.MethodGet, swaggerEndpoint+"/doc.json", nil)
require.NoError(t, err)

body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
defer resp.Body.Close()

require.Contains(t, string(body), "Slim build of Coder")
require.Equal(t, http.StatusNotFound, resp.StatusCode)
})
}

Expand Down