Skip to content

Commit 9e817e6

Browse files
committed
feat(googlereader)!: remove CORS handler
The Google Reader API is not supposed to be used by web clients. Removing CORS should not break any Google Reader client and it reduces the attack surface.
1 parent 5594586 commit 9e817e6

File tree

2 files changed

+0
-15
lines changed

2 files changed

+0
-15
lines changed

internal/googlereader/handler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ func Serve(router *mux.Router, store *storage.Storage) {
4747

4848
middleware := newMiddleware(store)
4949
sr := router.PathPrefix("/reader/api/0").Subrouter()
50-
sr.Use(middleware.handleCORS)
5150
sr.Use(middleware.apiKeyAuth)
52-
sr.Methods(http.MethodOptions)
5351
sr.HandleFunc("/token", handler.tokenHandler).Methods(http.MethodGet).Name("Token")
5452
sr.HandleFunc("/edit-tag", handler.editTagHandler).Methods(http.MethodPost).Name("EditTag")
5553
sr.HandleFunc("/rename-tag", handler.renameTagHandler).Methods(http.MethodPost).Name("Rename Tag")

internal/googlereader/middleware.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,6 @@ func newMiddleware(s *storage.Storage) *middleware {
2525
return &middleware{s}
2626
}
2727

28-
func (m *middleware) handleCORS(next http.Handler) http.Handler {
29-
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
30-
w.Header().Set("Access-Control-Allow-Origin", "*")
31-
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
32-
w.Header().Set("Access-Control-Allow-Headers", "Authorization")
33-
if r.Method == http.MethodOptions {
34-
w.WriteHeader(http.StatusOK)
35-
return
36-
}
37-
next.ServeHTTP(w, r)
38-
})
39-
}
40-
4128
func (m *middleware) apiKeyAuth(next http.Handler) http.Handler {
4229
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
4330
clientIP := request.ClientIP(r)

0 commit comments

Comments
 (0)