@@ -265,7 +265,7 @@ func ShouldCacheFile(reqFile string) bool {
265
265
}
266
266
267
267
func (h * Handler ) serveHTML (resp http.ResponseWriter , request * http.Request , reqPath string , state htmlState ) bool {
268
- if data , err := h .renderHTMLWithState (resp , request , reqPath , state ); err == nil {
268
+ if data , err := h .renderHTMLWithState (request , reqPath , state ); err == nil {
269
269
if reqPath == "" {
270
270
// Pass "index.html" to the ServeContent so the ServeContent sets the right content headers.
271
271
reqPath = "index.html"
@@ -278,7 +278,7 @@ func (h *Handler) serveHTML(resp http.ResponseWriter, request *http.Request, req
278
278
279
279
// renderWithState will render the file using the given nonce if the file exists
280
280
// as a template. If it does not, it will return an error.
281
- func (h * Handler ) renderHTMLWithState (rw http. ResponseWriter , r * http.Request , filePath string , state htmlState ) ([]byte , error ) {
281
+ func (h * Handler ) renderHTMLWithState (r * http.Request , filePath string , state htmlState ) ([]byte , error ) {
282
282
var buf bytes.Buffer
283
283
if filePath == "" {
284
284
filePath = "index.html"
@@ -289,8 +289,11 @@ func (h *Handler) renderHTMLWithState(rw http.ResponseWriter, r *http.Request, f
289
289
}
290
290
291
291
// Cookies are sent when requesting HTML, so we can get the user
292
- // and pre-populate the state for the frontend to reduce requests.
293
- apiKey , actor , _ := httpmw .ExtractAPIKey (rw , r , httpmw.ExtractAPIKeyConfig {
292
+ // and pre-populate the state for the frontend to reduce requests,
293
+ // however we don't want to return any errors here because we don't
294
+ // want to break the page if there's a problem with OAuth.
295
+ noopRW := noopResponseWriter {}
296
+ apiKey , actor , ok := httpmw .ExtractAPIKey (noopRW , r , httpmw.ExtractAPIKeyConfig {
294
297
Optional : true ,
295
298
DB : h .opts .Database ,
296
299
OAuth2Configs : h .opts .OAuth2Configs ,
@@ -300,7 +303,7 @@ func (h *Handler) renderHTMLWithState(rw http.ResponseWriter, r *http.Request, f
300
303
RedirectToLogin : false ,
301
304
SessionTokenFunc : nil ,
302
305
})
303
- if apiKey != nil && actor != nil {
306
+ if ok && apiKey != nil && actor != nil {
304
307
ctx := dbauthz .As (r .Context (), actor .Actor )
305
308
306
309
var eg errgroup.Group
@@ -392,6 +395,13 @@ func (h *Handler) renderHTMLWithState(rw http.ResponseWriter, r *http.Request, f
392
395
return buf .Bytes (), nil
393
396
}
394
397
398
+ // noopResponseWriter is a response writer that does nothing.
399
+ type noopResponseWriter struct {}
400
+
401
+ func (noopResponseWriter ) Header () http.Header { return http.Header {} }
402
+ func (noopResponseWriter ) Write (p []byte ) (int , error ) { return len (p ), nil }
403
+ func (noopResponseWriter ) WriteHeader (int ) {}
404
+
395
405
// secureHeaders is only needed for statically served files. We do not need this for api endpoints.
396
406
// It adds various headers to enforce browser security features.
397
407
func secureHeaders () * secure.Secure {
0 commit comments