AI pentesting guides / By tech stack

Stack guide: Go

Go API security testing

Go API security testing looks for logic and configuration flaws rather than memory corruption: Go is memory-safe and its standard library is conservative, so the bugs that matter are missing authorisation in handlers, SSRF in code that fetches URLs, string-built SQL and debug endpoints left mounted.

Go services are often small and numerous, built with net/http, chi, gin, echo or fiber. Each router composes middleware differently, so it is worth checking that auth applies to every group, not just the first one written.

Routing and middleware

  • Middleware applied to one route group but not another (r.Group in chi or gin) leaves sibling routes unprotected.
  • Handlers that read a user ID from a header or query parameter instead of the verified token context.
  • net/http/pprof imported for debugging registers /debug/pprof on the default mux, exposing profiles and goroutine dumps.
  • expvar at /debug/vars can leak configuration and counters.

Data handling

  • fmt.Sprintf into database/sql queries bypasses placeholders; ORMs such as GORM are safe only with bound parameters.
  • encoding/json ignores unknown fields by default and matches keys case-insensitively, so decoding into a struct with an IsAdmin field enables mass assignment unless input and storage types are separate.
  • Webhook and URL-preview features using http.Get on user URLs are classic SSRF; check redirects and internal ranges, including cloud metadata.
  • exec.Command with sh -c and user input gives command injection.

Operational defaults

http.ListenAndServe with a zero-value http.Server has no read or write timeouts, which makes slow-client resource exhaustion easier. Missing request body limits allow large uploads to exhaust memory. JWT libraries need the expected signing method checked explicitly. None of these are exotic; they are just not on by default.

gRPC gateways and internal APIs

Many Go services expose gRPC internally and REST externally through grpc-gateway. Authorisation implemented as a gRPC interceptor protects both paths, while checks written only in the HTTP layer can be bypassed if the gRPC port is reachable. Testers confirm which ports answer, whether gRPC server reflection is enabled, and whether internal admin RPCs are exposed through the gateway's generated routes.

With Pentest-Swarm

Running Pentest-Swarm against a Go service

Pentest-Swarm is itself written in Go, but it tests your Go API the same way it tests anything else: over HTTP, from outside.

  • Recon checks /swagger/doc.json (the swaggo default) and other spec paths, and maps documented routes.
  • The api-security playbook tests BOLA, BFLA and mass assignment with test tokens passed via --auth.
  • SSRF findings are confirmed with out-of-band callbacks when you run with --verify.
  • Point the run at each service's staging URL, and use the --targets option to batch several services with per-target reports.

Where it falls short

A black-box test will not catch a race condition or goroutine leak that does not show up in responses, and it cannot read go.mod. Run govulncheck for known vulnerabilities in reachable code, gosec for static issues, and the race detector in tests.

Questions

Is Go safer than other languages for APIs?

It removes memory-safety bugs and has sensible standard libraries. Authorisation, injection and SSRF are application logic, and Go does not prevent them.

Is exposing /debug/pprof a vulnerability?

On a public interface, yes. It reveals internals and can be used to consume CPU. Serve it on a separate, internal-only listener.

Can I test many Go microservices at once?

Yes. Pentest-Swarm accepts multiple targets as a sequential batch and produces per-target reports plus a roll-up.