From bacf2afed1e5f0abd92603274254c13b01e1dbc2 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 19 Dec 2022 17:52:07 +0100 Subject: [PATCH] internal: remove sentry proxy Signed-off-by: Jens Langhammer --- internal/web/sentry_proxy.go | 78 ------------------------------------ internal/web/web.go | 5 --- web/src/common/sentry.ts | 1 - 3 files changed, 84 deletions(-) delete mode 100644 internal/web/sentry_proxy.go diff --git a/internal/web/sentry_proxy.go b/internal/web/sentry_proxy.go deleted file mode 100644 index 378eab9b9..000000000 --- a/internal/web/sentry_proxy.go +++ /dev/null @@ -1,78 +0,0 @@ -package web - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "net/http" - "net/url" - "strconv" - "strings" - - "goauthentik.io/internal/config" -) - -type SentryRequest struct { - DSN string `json:"dsn"` -} - -func (ws *WebServer) APISentryProxy() http.HandlerFunc { - fallbackHandler := func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusBadRequest) - } - if !config.Get().ErrorReporting.Enabled { - ws.log.Debug("error reporting disabled") - return fallbackHandler - } - dsn, err := url.Parse(config.Get().ErrorReporting.SentryDSN) - if err != nil { - ws.log.WithError(err).Warning("invalid sentry DSN") - return fallbackHandler - } - projectId, err := strconv.Atoi(strings.TrimPrefix(dsn.Path, "/")) - if err != nil { - ws.log.WithError(err).Warning("failed to get sentry project id") - return fallbackHandler - } - return func(rw http.ResponseWriter, r *http.Request) { - fb := &bytes.Buffer{} - _, err := io.Copy(fb, r.Body) - if err != nil { - ws.log.Debug("failed to read body") - rw.WriteHeader(http.StatusBadRequest) - return - } - lines := strings.Split(fb.String(), "\n") - if len(lines) < 1 { - rw.WriteHeader(http.StatusBadRequest) - return - } - sd := SentryRequest{} - err = json.Unmarshal([]byte(lines[0]), &sd) - if err != nil { - ws.log.WithError(err).Warning("failed to parse sentry request") - rw.WriteHeader(http.StatusBadRequest) - return - } - if sd.DSN != config.Get().ErrorReporting.SentryDSN { - rw.WriteHeader(http.StatusBadRequest) - return - } - res, err := http.DefaultClient.Post( - fmt.Sprintf( - "https://%s/api/%d/envelope/", - dsn.Host, - projectId, - ), - "application/x-sentry-envelope", - fb, - ) - if err != nil { - ws.log.WithError(err).Warning("failed to proxy sentry") - rw.WriteHeader(http.StatusBadRequest) - return - } - rw.WriteHeader(res.StatusCode) - } -} diff --git a/internal/web/web.go b/internal/web/web.go index 13422ea54..8e440bd2a 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -47,15 +47,10 @@ func NewWebServer(g *gounicorn.GoUnicorn) *WebServer { p: g, } ws.configureStatic() - ws.configureRoutes() ws.configureProxy() return ws } -func (ws *WebServer) configureRoutes() { - ws.m.Path("/api/v3/sentry/").HandlerFunc(ws.APISentryProxy()) -} - func (ws *WebServer) Start() { go ws.listenPlain() go ws.listenTLS() diff --git a/web/src/common/sentry.ts b/web/src/common/sentry.ts index 31c7c705d..f89a35f13 100644 --- a/web/src/common/sentry.ts +++ b/web/src/common/sentry.ts @@ -27,7 +27,6 @@ export async function configureSentry(canDoPpi = false): Promise { /NS_ERROR_FAILURE/gi, ], release: `authentik@${VERSION}`, - tunnel: "/api/v3/sentry/", integrations: [ new Integrations.BrowserTracing({ tracingOrigins: [window.location.host, "localhost"],