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
11 changes: 6 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ jobs:
security:
name: Security Scanning
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4

Expand All @@ -103,15 +105,14 @@ jobs:
go-version-file: 'go.mod'

- name: Run govulncheck
continue-on-error: true
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
go install golang.org/x/vuln/cmd/govulncheck@v1.1.4
govulncheck ./...
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

govulncheck is run without the opa_no_wasm build tag, while the main build/test jobs compile with -tags opa_no_wasm. This means govulncheck may skip analysis of the tagged code paths (e.g., pkg/pdp/config.go) and can miss vulnerabilities that ship in the intended build. Consider passing the same build tags to govulncheck (or running it for both tag sets).

Suggested change
govulncheck ./...
govulncheck -tags opa_no_wasm ./...

Copilot uses AI. Check for mistakes.
Comment on lines +109 to 110
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description says govulncheck is pinned to v1.1.3, but this workflow installs v1.1.4. Either update the PR description or change the pinned version so the remediation record matches what CI actually enforces.

Copilot uses AI. Check for mistakes.

- name: Run gosec (SAST)
uses: securego/gosec@master
with:
args: '-no-fail -fmt json -out gosec-results.json ./...'
run: |
go install github.com/securego/gosec/v2/cmd/gosec@v2.22.4
gosec -exclude-generated -exclude=G115,G304,G107 -fmt json -out gosec-results.json ./...

- name: Upload gosec results
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion cmd/capiscio/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ Example:

// Write to file if requested
if requestOutFile != "" {
if err := os.WriteFile(requestOutFile, []byte(result.Token), 0644); err != nil {
if err := os.WriteFile(requestOutFile, []byte(result.Token), 0600); err != nil {
return fmt.Errorf("failed to write badge to file: %w", err)
}
fmt.Printf("\n📝 Badge saved to: %s\n", requestOutFile)
Expand Down
9 changes: 8 additions & 1 deletion cmd/capiscio/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"time"

"github.com/capiscio/capiscio-core/v2/pkg/badge"
"github.com/capiscio/capiscio-core/v2/pkg/gateway"
Expand Down Expand Up @@ -56,8 +57,14 @@ var gatewayStartCmd = &cobra.Command{

// 5. Start Server
addr := fmt.Sprintf(":%d", gatewayPort)
srv := &http.Server{
Addr: addr,
Handler: handler,
ReadHeaderTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
}
log.Printf("Gateway listening on %s -> %s", addr, gatewayTarget)
return http.ListenAndServe(addr, handler)
return srv.ListenAndServe()
},
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/capiscio/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,15 @@ func generateAndSaveKeys(outputDir string) (ed25519.PublicKey, ed25519.PrivateKe
return nil, nil, "", jose.JSONWebKey{}, fmt.Errorf("failed to marshal public key: %w", err)
}
publicKeyPath := filepath.Join(outputDir, "public.jwk")
// #nosec G306 -- public key material
if err := os.WriteFile(publicKeyPath, pubBytes, 0644); err != nil {
return nil, nil, "", jose.JSONWebKey{}, fmt.Errorf("failed to write public key: %w", err)
}
fmt.Printf("✅ Public key saved: %s\n", publicKeyPath)

// Save DID
didPath := filepath.Join(outputDir, "did.txt")
// #nosec G306 -- DID is public identifier
if err := os.WriteFile(didPath, []byte(didKey+"\n"), 0644); err != nil {
return nil, nil, "", jose.JSONWebKey{}, fmt.Errorf("failed to write DID: %w", err)
}
Expand Down Expand Up @@ -279,6 +281,7 @@ func saveAgentCard(outputDir, agentID, agentName, didKey, serverURL string, pubJ
if err != nil {
return fmt.Errorf("failed to marshal agent card: %w", err)
}
// #nosec G306 -- agent cards are public-facing metadata
if err := os.WriteFile(agentCardPath, cardBytes, 0644); err != nil {
return fmt.Errorf("failed to write agent card: %w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/capiscio/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ self-signed Trust Badges.`,
if err != nil {
return err
}
// #nosec G306 -- public key material
if err := os.WriteFile(keyOutPublic, pubBytes, 0644); err != nil {
return fmt.Errorf("failed to write public key: %w", err)
}
fmt.Printf("✅ Public Key saved to %s\n", keyOutPublic)

// 6. Output did:key identifier
if keyOutDID != "" {
// #nosec G306 -- DID is public identifier
if err := os.WriteFile(keyOutDID, []byte(didKey+"\n"), 0644); err != nil {
return fmt.Errorf("failed to write did:key: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/capiscio/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func runPolicyContext(_ *cobra.Command, _ []string) error {
}

if policyOutput != "" {
if err := os.WriteFile(policyOutput, append(output, '\n'), 0644); err != nil {
if err := os.WriteFile(policyOutput, append(output, '\n'), 0600); err != nil {
return fmt.Errorf("write output file: %w", err)
}
fmt.Printf("✅ Policy context written to %s\n", policyOutput)
Expand Down
8 changes: 7 additions & 1 deletion examples/secure_ping_pong/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"log"
"net/http"
"time"

"github.com/capiscio/capiscio-core/v2/pkg/simpleguard"
)
Expand Down Expand Up @@ -73,7 +74,12 @@ func main() {

log.Println("🛡️ Secure Ping Pong Server running on :8080")
log.Println(" Waiting for signed requests...")
if err := http.ListenAndServe(":8080", mux); err != nil {
srv := &http.Server{
Addr: ":8080",
Handler: mux,
ReadHeaderTimeout: 10 * time.Second,
}
if err := srv.ListenAndServe(); err != nil {
log.Fatal(err)
}
Comment on lines +82 to 84
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListenAndServe returns http.ErrServerClosed on normal shutdown; calling log.Fatal on any error can make graceful shutdown paths look like failures. Consider special-casing http.ErrServerClosed (or using errors.Is) before logging fatally.

Copilot uses AI. Check for mistakes.
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/capiscio/capiscio-core/v2

go 1.25.0
go 1.25.8
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go directive should not include a non-zero patch version (e.g., 1.25.8). The go directive is the language version and Go tooling expects x.y or x.y.0; using 1.25.8 can make go mod parsing fail and break actions/setup-go when using go-version-file. Keep go 1.25.0 (or go 1.25) and, if you need to pin the toolchain patch, add a separate toolchain go1.25.8 directive instead.

Suggested change
go 1.25.8
go 1.25.0
toolchain go1.25.8

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go 1.25.8 makes the security job (which uses go-version-file: go.mod) run a different Go patch version than the lint/test jobs pinned to 1.25.0 in .github/workflows/ci.yml. Align these (e.g., use go-version-file everywhere or bump the pinned versions) to avoid inconsistent CI results.

Suggested change
go 1.25.8
go 1.25.0

Copilot uses AI. Check for mistakes.

require (
github.com/go-jose/go-jose/v4 v4.1.3
github.com/google/uuid v1.6.0
github.com/open-policy-agent/opa v1.14.1
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
google.golang.org/grpc v1.79.1
google.golang.org/grpc v1.79.3
google.golang.org/protobuf v1.36.11
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 h1:H86B94AW+VfJWDqFeEbBPhEtHzJwJfTbgE2lZa54ZAQ=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409/go.mod h1:j9x/tPzZkyxcgEFkiKEEGxfvyumM01BEtsW8xzOahRQ=
google.golang.org/grpc v1.79.1 h1:zGhSi45ODB9/p3VAawt9a+O/MULLl9dpizzNNpq7flY=
google.golang.org/grpc v1.79.1/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
google.golang.org/grpc v1.79.3 h1:sybAEdRIEtvcD68Gx7dmnwjZKlyfuc61Dyo9pGXXkKE=
google.golang.org/grpc v1.79.3/go.mod h1:KmT0Kjez+0dde/v2j9vzwoAScgEPx/Bw1CYChhHLrHQ=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
2 changes: 2 additions & 0 deletions internal/rpc/simpleguard_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ func initGenerateAndSaveKeys(outputDir string) (*initKeyResult, error) {
}

pubKeyPath := filepath.Join(outputDir, "public.jwk")
// #nosec G306 -- public key material is intended to be readable
if err := os.WriteFile(pubKeyPath, pubJWKBytes, 0644); err != nil {
return nil, fmt.Errorf("failed to write public key: %v", err)
}
Expand Down Expand Up @@ -616,6 +617,7 @@ func (s *SimpleGuardService) Init(_ context.Context, req *pb.InitRequest) (*pb.I
}

agentCardPath := filepath.Join(outputDir, "agent-card.json")
// #nosec G306 -- agent cards are public-facing metadata
if err := os.WriteFile(agentCardPath, agentCardBytes, 0644); err != nil {
return &pb.InitResponse{ErrorMessage: fmt.Sprintf("failed to write agent card: %v", err)}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/badge/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (k *Keeper) renewSelfSign() (*RenewalResult, error) {

// Write to file
if k.config.OutputFile != "" {
if err := os.WriteFile(k.config.OutputFile, []byte(token), 0644); err != nil {
if err := os.WriteFile(k.config.OutputFile, []byte(token), 0600); err != nil {
return nil, fmt.Errorf("failed to write badge file: %w", err)
}
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/pdp/bundle_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ func (m *BundleManager) nextDelay() time.Duration {
}

// Add jitter: ±25% to prevent thundering herd
jitter := delay * 0.25 * (rand.Float64()*2 - 1) //nolint:gosec // jitter doesn't need crypto rand
// #nosec G404 -- jitter doesn't need crypto rand
jitter := delay * 0.25 * (rand.Float64()*2 - 1) //nolint:gosec
delay += jitter

return time.Duration(delay)
Expand Down
Loading