Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CLAUDE.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ require (
github.com/google/jsonschema-go v0.4.3
github.com/modelcontextprotocol/go-sdk v1.8.0
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
golang.org/x/oauth2 v0.35.0
golang.org/x/sync v0.24.0
golang.org/x/term v0.48.0
)

require (
github.com/golang/snappy v0.0.4 // indirect
github.com/segmentio/asm v1.1.3 // indirect
github.com/segmentio/encoding v0.5.4 // indirect
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
golang.org/x/oauth2 v0.35.0 // indirect
golang.org/x/sys v0.49.0 // indirect
golang.org/x/sys v0.50.0 // indirect
golang.org/x/time v0.15.0 // indirect
golang.org/x/tools v0.52.0 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/sys v0.50.0 h1:dkKZEFTEKaLr1sjhs0WiKqoi8Jj5nHbS3Njmx1UoMJs=
golang.org/x/sys v0.50.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.48.0 h1:G6UU1eiSB8nl3DzeUGt7Mg+2SctI8tPS6Z5/mBt6cOk=
golang.org/x/term v0.48.0/go.mod h1:BRDLHCZr2SUjIeBHHpRyQeC9xzSAVbzY2rvKgafnHf4=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
4 changes: 3 additions & 1 deletion internal/api/google_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ func newFakeGoogle(t *testing.T) *fakeGoogle {

payload, _ := json.Marshal(google.account)
token := "e30." + base64.RawURLEncoding.EncodeToString(payload) + ".signature"
_ = json.NewEncoder(w).Encode(map[string]string{"id_token": token})

w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]string{"access_token": "access-1", "token_type": "Bearer", "id_token": token})
}))
t.Cleanup(google.Close)

Expand Down
5 changes: 3 additions & 2 deletions internal/api/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"strings"

"github.com/modelcontextprotocol/go-sdk/auth"
"github.com/modelcontextprotocol/go-sdk/mcp"

"github.com/devforth/exceptic/internal/oauth"
Expand Down Expand Up @@ -63,6 +62,8 @@ func NewMCP(logger *slog.Logger, database store.Store, projects config.ProjectLi
}, &mcp.StreamableHTTPOptions{
Stateless: true,
JSONResponse: true,
// The REST cap plus room for the JSON-RPC frame around a tool's arguments.
MaxRequestBodyBytes: maxBody + 1<<10,
// The SDK rejects requests to a localhost address with another Host
// (DNS rebinding of a local server without auth). Behind a reverse
// proxy on the same machine every request looks like that, and the
Expand Down Expand Up @@ -192,7 +193,7 @@ type callerKey struct{}
// reached it, for DSNs. It runs after oauth.Protect has checked the token.
func (handler *MCP) withCaller(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
grant, ok := oauth.GrantOf(auth.TokenInfoFromContext(r.Context()))
grant, ok := oauth.GrantOf(r.Context())

if !ok {
handler.logger.Error("mcp request without its grant", "path", r.URL.Path)
Expand Down
26 changes: 26 additions & 0 deletions internal/api/mcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,32 @@ func TestRequiresToken(t *testing.T) {
}
}

func TestLargeBodyRefused(t *testing.T) {
server := newTestServer(t)
body := `{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"list_issues","arguments":{"query":"` + strings.Repeat("x", 80<<10) + `"}}}`
request, err := http.NewRequest(http.MethodPost, server.url, strings.NewReader(body))

if err != nil {
t.Fatal(err)
}

request.Header.Set("Content-Type", "application/json")
request.Header.Set("Accept", "application/json, text/event-stream")
request.Header.Set("Authorization", "Bearer "+server.token)

response, err := http.DefaultClient.Do(request)

if err != nil {
t.Fatal(err)
}

_ = response.Body.Close()

if response.StatusCode != http.StatusRequestEntityTooLarge {
t.Errorf("%d, want 413", response.StatusCode)
}
}

func TestSkillsDiscoveryAndLoading(t *testing.T) {
server := newTestServer(t)
session := server.connect()
Expand Down
31 changes: 11 additions & 20 deletions internal/ingest/grouping/variables.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package grouping

import (
"cmp"
"regexp"
"strings"

Expand Down Expand Up @@ -56,7 +57,7 @@ func variable(event *sentry.Event, name string) (value, placeholder string, ok b
case "transaction":
return event.Transaction, "<no-transaction>", true
case "message":
return firstNonEmpty(string(event.Message), mainException(event).Value), "<no-message>", true
return cmp.Or(string(event.Message), mainException(event).Value), "<no-message>", true
case "level":
return eventLevel(event), "<no-level>", true
case "logger":
Expand All @@ -70,11 +71,11 @@ func variable(event *sentry.Event, name string) (value, placeholder string, ok b
case "stack.abs_path", "path":
frame := crashFrame(event)

return firstNonEmpty(frame.AbsPath, frame.Filename), "<no-abs-path>", true
return cmp.Or(frame.AbsPath, frame.Filename), "<no-abs-path>", true
case "stack.filename":
frame := crashFrame(event)

return firstNonEmpty(frame.Filename, frame.AbsPath), "<no-filename>", true
return cmp.Or(frame.Filename, frame.AbsPath), "<no-filename>", true
case "stack.module", "module":
return crashFrame(event).Module, "<no-module>", true
case "stack.package", "package":
Expand All @@ -94,21 +95,21 @@ func tagValue(event *sentry.Event, name string) string {
case "level":
return eventLevel(event)
case "environment":
return firstNonEmpty(event.Environment, sent)
return cmp.Or(event.Environment, sent)
case "logger":
return firstNonEmpty(event.Logger, sent)
return cmp.Or(event.Logger, sent)
case "transaction":
return firstNonEmpty(event.Transaction, sent)
return cmp.Or(event.Transaction, sent)
case "server_name":
return firstNonEmpty(event.ServerName, sent)
return cmp.Or(event.ServerName, sent)
case "sentry:release":
return firstNonEmpty(event.Release, sent)
return cmp.Or(event.Release, sent)
case "sentry:dist":
if event.Release != "" {
return firstNonEmpty(event.Dist, sent)
return cmp.Or(event.Dist, sent)
}
case "sentry:user":
return firstNonEmpty(userTag(event.User), sent)
return cmp.Or(userTag(event.User), sent)
case "release", "dist", "user", "filename", "function":
return ""
}
Expand Down Expand Up @@ -202,16 +203,6 @@ func culpritFrame(event *sentry.Event) sentry.Frame {
return frames[len(frames)-1]
}

func firstNonEmpty(values ...string) string {
for _, value := range values {
if value != "" {
return value
}
}

return ""
}

func lastPathSegment(path string) string {
return path[strings.LastIndexAny(path, `/\`)+1:]
}
8 changes: 1 addition & 7 deletions internal/ingest/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,7 @@ func (pipeline *Pipeline) Run(ctx context.Context) {
var processors sync.WaitGroup

for range workers {
processors.Add(1)

go func() {
defer processors.Done()

pipeline.processEntries(entries, results, budget)
}()
processors.Go(func() { pipeline.processEntries(entries, results, budget) })
}

writerDone, sharesDone := make(chan struct{}), make(chan struct{})
Expand Down
26 changes: 11 additions & 15 deletions internal/ingest/scrub.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/json"
"encoding/json/jsontext"
jsonv2 "encoding/json/v2"
"io"
"net/url"
"regexp"
Expand Down Expand Up @@ -260,9 +261,12 @@ func newTokenDecoder(payload []byte) *jsontext.Decoder {
return jsontext.NewDecoder(bytes.NewReader(payload), jsontext.AllowDuplicateNames(true), jsontext.AllowInvalidUTF8(true))
}

// tokenWriting writes compactly, without HTML escaping: the scrubbed output and the copy it is compared with.
var tokenWriting = []jsontext.Options{jsontext.EscapeForHTML(false), jsontext.AllowDuplicateNames(true), jsontext.AllowInvalidUTF8(true)}

// newTokenEncoder writes a token stream compactly, without HTML escaping.
func newTokenEncoder(output io.Writer) *jsontext.Encoder {
return jsontext.NewEncoder(output, jsontext.EscapeForHTML(false), jsontext.AllowDuplicateNames(true), jsontext.AllowInvalidUTF8(true))
return jsontext.NewEncoder(output, tokenWriting...)
}

// scrubJSON returns payload with credentials replaced, read and written as one
Expand Down Expand Up @@ -1023,17 +1027,9 @@ func hasValueMember(object jsontext.Value) bool {
return false
}

// writeJSON writes a decoded tree into the stream, objects' names sorted as encoding/json sorts them.
func writeJSON(encoder *jsontext.Encoder, value any) error {
var output bytes.Buffer

writer := json.NewEncoder(&output)
writer.SetEscapeHTML(false)

if err := writer.Encode(value); err != nil {
return err
}

return encoder.WriteValue(bytes.TrimRight(output.Bytes(), "\n"))
return jsonv2.MarshalEncode(encoder, value, jsonv2.Deterministic(true))
}

// scrubText removes credentials from a string of a payload: a JSON document
Expand Down Expand Up @@ -1226,17 +1222,17 @@ func scrubJSONText(text string) (string, bool) {
}

// Both are written the same way, so they differ only where a value was replaced.
var compact bytes.Buffer
compact, written := jsontext.Value(trimmed), bytes.TrimRight(scrubbed.Bytes(), "\n")

if value, err := newTokenDecoder([]byte(trimmed)).ReadValue(); err != nil || newTokenEncoder(&compact).WriteValue(value) != nil {
if compact.Format(tokenWriting...) != nil {
return "", false
}

if bytes.Equal(scrubbed.Bytes(), compact.Bytes()) {
if bytes.Equal(written, compact) {
return text, true
}

return string(bytes.TrimRight(scrubbed.Bytes(), "\n")), true
return string(written), true
}

// scrubQuotedPairs replaces the value of every "key": value pair of JSON,
Expand Down
Loading
Loading