Skip to content

Commit 658d7df

Browse files
committed
fix: relax csrf to exclude path based apps
1 parent c6366e5 commit 658d7df

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

coderd/coderd.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,6 @@ func New(options *Options) *API {
579579
next.ServeHTTP(w, r)
580580
})
581581
},
582-
httpmw.CSRF(options.SecureAuthCookie),
583582
)
584583

585584
r.Get("/healthz", func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("OK")) })
@@ -627,6 +626,10 @@ func New(options *Options) *API {
627626
// limit must be configurable by the admin.
628627
apiRateLimiter,
629628
httpmw.ReportCLITelemetry(api.Logger, options.Telemetry),
629+
// CSRF only needs to apply to /api routes. It does not apply to GET requests
630+
// anyway, which is most other routes. We want to exempt any external auth or
631+
// application type routes.
632+
httpmw.CSRF(options.SecureAuthCookie),
630633
)
631634
r.Get("/", apiRoot)
632635
// All CSP errors will be logged

enterprise/wsproxy/wsproxy.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,10 @@ func New(ctx context.Context, opts *Options) (*Server, error) {
329329
next.ServeHTTP(w, r)
330330
})
331331
},
332-
// TODO: @emyrk we might not need this? But good to have if it does
333-
// not break anything.
334-
httpmw.CSRF(s.Options.SecureAuthCookie),
332+
// CSRF middleware is intentionally excluded here. All coder requests
333+
// which require CSRF protection are forwarded to the primary Coderd
334+
// via a proxy function. Since the primary enforces this, the proxy does
335+
// not.
335336
)
336337

337338
// Attach workspace apps routes.

0 commit comments

Comments
 (0)