Skip to content

Commit

Permalink
Support gzip optional decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
n0str committed Dec 18, 2024
1 parent e047330 commit 61471d5
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions pkg/server/errorshandler/handler_sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,46 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
return
}

var auth []byte
var hawkToken string
var err error

// parse incoming get request params
auth = ctx.QueryArgs().Peek("sentry_key")
if auth == nil {
sentryKey := ctx.QueryArgs().Peek("sentry_key")
if sentryKey == nil {
log.Warnf("Incoming request with deprecated sentry_key parameter")

// check that X-Sentry-Auth header is available
auth = ctx.Request.Header.Peek("X-Sentry-Auth")
auth := ctx.Request.Header.Peek("X-Sentry-Auth")
if auth == nil {
log.Warnf("Incoming request without X-Sentry-Auth header")
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "X-Sentry-Auth header is missing"})
return
}
}

hawkToken, err := getSentryKeyFromAuth(string(auth))
if err != nil {
log.Warnf("Incoming request with invalid X-Sentry-Auth header=%s: %s", auth, err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: err.Error()})
return
hawkToken, err = getSentryKeyFromAuth(string(auth))
if err != nil {
log.Warnf("Incoming request with invalid X-Sentry-Auth header=%s: %s", auth, err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: err.Error()})
return
}
} else {
hawkToken = string(sentryKey)
}

log.Debugf("Incoming request with hawk integration token: %s", hawkToken)

body := ctx.PostBody()
sentryEnvelopeBody := ctx.PostBody()

sentryEnvelopeBody, err := decompressGzipString(body)
if err != nil {
log.Warnf("Failed to decompress gzip body: %s", err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "Failed to decompress gzip body"})
return
// todo: add check of gzip header
if sentryKey == nil {
sentryEnvelopeBody, err = decompressGzipString(sentryEnvelopeBody)
if err != nil {
log.Warnf("Failed to decompress gzip body: %s", err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "Failed to decompress gzip body"})
return
}
log.Debugf("Decompressed body: %s", sentryEnvelopeBody)
}
log.Debugf("Decompressed body: %s", sentryEnvelopeBody)

projectId, ok := handler.AccountsMongoDBClient.ValidTokens[hawkToken]
if !ok {
Expand Down

0 comments on commit 61471d5

Please sign in to comment.