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
26 changes: 26 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -3535,6 +3535,32 @@ Source: https://github.com/tuna-os/ccleft/blob/b243120bfda2/LICENSE

-----------------------------------------------------------------------------

Package: github.com/vektah/gqlparser/v2
Version: v2.5.30
License: MIT
Source: https://github.com/vektah/gqlparser/blob/v2.5.30/LICENSE

Copyright (c) 2018 Adam Scarr

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-----------------------------------------------------------------------------

Package: github.com/xo/terminfo
Version: v0.0.0-20220910002029-abceb7e1c41e
License: MIT
Expand Down
1 change: 1 addition & 0 deletions changelog.d/security-19058-graphql-repo-scope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Apply per-agent repository scope to attributable GitHub GraphQL mutations, including node-ID writes resolved from earlier GitHub responses, with the same denial as REST. Queries stay unrestricted; unresolved mutations retain existing gates for compatibility with normal `gh` flows ([#19058](https://github.com/hivecommons/hive/issues/19058)).
1 change: 1 addition & 0 deletions src/crux/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/nats-io/nats-server/v2 v2.15.3
github.com/nats-io/nats.go v1.55.0
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/vektah/gqlparser/v2 v2.5.30
go.opentelemetry.io/otel v1.47.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.47.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.47.0
Expand Down
2 changes: 2 additions & 0 deletions src/crux/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
github.com/vektah/gqlparser/v2 v2.5.30 h1:EqLwGAFLIzt1wpx1IPpY67DwUujF1OfzgEyDsLrN6kE=
github.com/vektah/gqlparser/v2 v2.5.30/go.mod h1:D1/VCZtV3LPnQrcPBeR/q5jkSQIPti0uYCP/RI0gIeo=
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/otel v1.47.0 h1:j7ALJ/zgkS7Z6aeJW09p8VC9804bC+PpeTfCD4XPnOM=
Expand Down
4 changes: 2 additions & 2 deletions src/crux/proxy/autonomy_enforcement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func TestAutonomyDemotedRepoPRWriteRefused(t *testing.T) {
hiveMode := agent.DefaultAgentMode("scanner", 5)
SetAutonomyRepoLevel("hivecommons/hive", 4)
setAutonomyRepoLevelForTest(t, "hivecommons/hive", 4)
modeAfterDemotion := autonomyModeForRepo("scanner", "hivecommons/hive", hiveMode)
if AllowedByMode(modeAfterDemotion, "POST", "/repos/hivecommons/hive/git/refs") {
t.Fatal("demoted L4 scanner must not be allowed to create PR branches")
Expand All @@ -21,7 +21,7 @@ func TestAutonomyDemotedRepoPRWriteRefused(t *testing.T) {

func TestAutonomyDemotedRepoGraphQLPRWriteRefused(t *testing.T) {
hiveMode := agent.DefaultAgentMode("scanner", 5)
SetAutonomyRepoLevel("hivecommons/hive", 4)
setAutonomyRepoLevelForTest(t, "hivecommons/hive", 4)
body := []byte(`{"query":"mutation { createPullRequest(input: {repositoryId: \"R\"}) { pullRequest { id } } }"}`)
allowed, mutation := GraphQLAllowedCaps(autonomyGraphQLMode("scanner", body, hiveMode), agent.AgentCapabilities{}, body)
if !mutation {
Expand Down
1 change: 1 addition & 0 deletions src/crux/proxy/github_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var (
// GitHubProxy is an HTTP CONNECT proxy that performs MITM TLS
// inspection on GitHub API traffic and enforces ACMM mode rules.
type GitHubProxy struct {
graphQLRepos graphQLRepoCache
// localInferencePaths records CLI telemetry paths already logged once by
// localInferenceResponse, so per-path DEBUG lines do not repeat.
localInferencePaths sync.Map
Expand Down
17 changes: 16 additions & 1 deletion src/crux/proxy/github_proxy_mitm.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (p *GitHubProxy) proxyHTTPHost(client net.Conn, upstream net.Conn, host str
// as paused even when the agent is also out of scope for it.
blockJSON := false
graphQLMutation := false
var graphQLBody []byte
// A direct write from a lane under write_surface.enforce (#9772) is
// refused and audited as agent_write_refused. Checked after pause and
// scope so their more specific reasons win when both apply.
Expand Down Expand Up @@ -155,7 +156,12 @@ func (p *GitHubProxy) proxyHTTPHost(client net.Conn, upstream net.Conn, host str
p.logTimeout("proxy GraphQL request body read timed out", readErr, "agent", agentName, "path", req.URL.Path)
return
}
if reason, refused := p.graphQLAutoMergeRefusal(body); agentName != internalCallerName && refused {
graphQLBody = body
if reason, refused := p.graphQLAgentRepoScopeRefusal(agentName, body); agentName != internalCallerName && refused {
blocked = true
blockReason = reason
blockCode = DenyReasonAgentRepoScope
} else if reason, refused := p.graphQLAutoMergeRefusal(body); agentName != internalCallerName && refused {
blocked = true
blockReason = reason
blockCode = DenyReasonRepoAutoMergeOff
Expand Down Expand Up @@ -415,6 +421,15 @@ func (p *GitHubProxy) proxyHTTPHost(client net.Conn, upstream net.Conn, host str
// longer than responseBodyStallTimeout errors out and lets the
// handler's deferred Closes reclaim the sockets.
resp.Body = &stallBoundedBody{body: resp.Body, conn: upstream, idle: p.bodyStallTimeoutDuration()}
if graphQLBody != nil && resp.StatusCode == http.StatusOK {
resp.Body = &graphQLRepoCapture{
ReadCloser: resp.Body,
length: resp.ContentLength,
observe: func(body []byte) {
p.observeGraphQLRepoResponse(agentName, graphQLBody, body, resp.Header.Get("Content-Encoding"))
},
}
}

// Rolling per-Write deadline (see stallBoundedWriter): a response that
// keeps flowing is never cut for being long, while a client that stops
Expand Down
70 changes: 70 additions & 0 deletions src/crux/proxy/graphql_repo_capture_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package proxy

import (
"bytes"
"compress/gzip"
"io"
"strings"
"testing"
)

func TestGraphQLRepoCapturePublishesBeforeFinalBytes(t *testing.T) {
for _, length := range []int64{3, -1} {
observed := false
capture := &graphQLRepoCapture{
ReadCloser: io.NopCloser(strings.NewReader("abc")),
length: length,
observe: func(body []byte) {
if string(body) != "abc" {
t.Errorf("observed %q", body)
}
observed = true
},
}
if length == 3 {
// HTTP relays with Content-Length may never perform an EOF read.
body := make([]byte, 3)
if _, err := io.ReadFull(capture, body); err != nil {
t.Fatal(err)
}
} else {
if _, err := io.Copy(io.Discard, capture); err != nil {
t.Fatal(err)
}
}
if !observed {
t.Fatalf("length=%d: response completed before cache publication", length)
}
}
}

func TestGraphQLRepoResponseBadEncodingAndGzipLimit(t *testing.T) {
lookup := scopeGraphQLBody(`query { repository(owner:"acme",name:"widgets"){id} }`, nil)
for _, tc := range []struct {
encoding string
body []byte
}{
{"gzip", []byte("broken")},
{"br", []byte(`{"data":{"repository":{"id":"R"}}}`)},
{"gzip", gzipScopeResponse(t, []byte(strings.Repeat(" ", graphQLRepoResponseLimit)+`{"data":{"repository":{"id":"R"}}}`))},
} {
p := newTestProxy()
p.observeGraphQLRepoResponse("schema", lookup, tc.body, tc.encoding)
if p.graphQLRepos.get("schema", "R") != "" {
t.Fatal("invalid/oversized response seeded cache")
}
}
}

func gzipScopeResponse(t *testing.T, body []byte) []byte {
t.Helper()
var buf bytes.Buffer
writer := gzip.NewWriter(&buf)
if _, err := writer.Write(body); err != nil {
t.Fatal(err)
}
if err := writer.Close(); err != nil {
t.Fatal(err)
}
return buf.Bytes()
}
Loading
Loading