All jobs

Fix Vulnerable Go Modules in an Echo API

Yes. An agent runs govulncheck on your Echo API, replaces the modules it flags with the smallest safe change, bumps Go in CI, reruns the tests and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own sandbox and starts from go.mod, because the module list already tells most of the story. In an API like xesina/golang-echo-realworld-example-app it declares go 1.18, github.com/labstack/echo/v4 v4.1.16, github.com/jinzhu/gorm v1.9.8 with the SQLite dialect, github.com/dgrijalva/jwt-go v3.2.0+incompatible, github.com/swaggo/swag v1.6.5 with echo-swagger v1.0.0, gopkg.in/go-playground/validator.v9, stretchr/testify v1.4.0 and golang.org/x/crypto, x/net, x/sys and x/text at pseudo-versions from 2020 and 2021. utils/jwt.go signs tokens with jwt.SigningMethodHS256 and a hard-coded JWTSecret, router/middleware/jwt.go parses them with jwt.Parse and jwt.MapClaims, and model/user.go hashes passwords with golang.org/x/crypto/bcrypt. .github/workflows/go.yml runs go build and go test on actions/setup-go@v3 with Go 1.18, the Makefile runs go test -v -race ./..., and the Dockerfile still builds in golang:1.12.1, older than the go directive.

It then runs govulncheck ./... and saves the output, because the report separates what matters from what merely appears in the module graph: a finding is listed as called from this code, or as present in a dependency but never reached. dgrijalva/jwt-go carries GO-2020-0017 (CVE-2020-26160, an audience check that passes when aud is a list), and the Go vulnerability database lists every version of that module as affected with no fixed release. Whether or not govulncheck marks it reachable here, there is no version to upgrade to, so the agent moves both files to github.com/golang-jwt/jwt/v4, the maintained fork that keeps SigningMethodHS256, MapClaims and Parse under the same names; the diff is an import path and a go get. Reports against the old x/crypto, x/net and x/sys are fixed by go get of those four modules to current versions, not by go get -u ./..., which would also move GORM and Echo.

Findings against the standard library depend on the toolchain, not on go.mod, and a workflow pinned to Go 1.18 builds with every net/http fix since then missing. The agent raises the go directive and the setup-go version together to a currently supported release, and updates the Dockerfile builder image to match, since golang:1.12.1 predates module-aware builds of this project. It leaves GORM v1 alone: it has no advisory, and moving to gorm.io/gorm is an API migration that belongs in its own pull request, which the description says.

Then it proves the result. go mod tidy, go build ./... and go test -race ./... run in the sandbox; the handler tests in handler/*_test.go use the SQLite test database that db.TestDB creates and drop it in TestMain, so they need nothing installed. It runs govulncheck ./... once more and pastes the before and after side by side, and it notes two things it found but did not change: the signing secret is a constant in utils/jwt.go, and swag 1.6.5 still generates valid docs but is several majors behind.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Audit this Go module for vulnerable dependencies and fix them. Read go.mod, go.sum, every .go file that imports jwt-go or golang.org/x packages, .github/workflows/go.yml, the Makefile and the Dockerfile first. Install govulncheck, run it over ./... and save the full report, including which findings are reachable from this code. For each finding apply the smallest fix: replace github.com/dgrijalva/jwt-go with the maintained golang-jwt fork at the same API, move golang.org/x/crypto, x/net, x/sys and x/text to current versions with go get of those modules only, and raise the go directive, the setup-go version in CI and the Dockerfile builder image to a supported Go release. Do not upgrade GORM or Echo majors; say in the pull request why. Run go mod tidy, go build ./..., go test -race ./... and govulncheck again, and open a pull request with the before and after reports and the test output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

The pull request changes go.mod and go.sum, the two files that import the JWT library, the Go version in .github/workflows/go.yml and the builder image in Dockerfile. Its description has the first govulncheck report with each finding marked reachable or not, the second report after the changes, the go test -race output for every package, and a short list of what was left as is and why.

Each finding maps to one change, so a reviewer can read the diff line by line against the report. The JWT replacement is the one behavioural change worth attention: tokens signed before and after the merge verify the same way, because the fork kept the HS256 implementation and claim types, and the handler tests that sign up, log in and call protected routes with a Token header pass against the new module.

Before merging, a reviewer confirms the Go version the agent chose matches what their image registry and deploy target support, decides whether the hard-coded signing secret becomes an environment variable in a follow-up, and runs the workflow once so the new toolchain builds in CI as it did in the sandbox.

Run it on every new Go vulnerability report

Advisories arrive on their own schedule, so a weekly run finds most of them before anyone reads a feed. A job on your server sends this body each Monday for every Go repository you own, each with its own resources URL and a request_id that is a UUID v5 of the repository and the week, so a retry returns the run that already started instead of opening a second pull request. The key's webhook_url gets one run.completed per repository with the pull request in result, and a run whose audit is already clean ends with a short answer and no branch.

A team that prefers a schedule inside Rush creates an automation with a schedule trigger set to that morning in its own timezone, in the Project that has the repository. An automation run is not tied to a key, so the key's webhook does not report it; it has its own max_runs_per_hour cap and appears in the Project like any other run.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

A Go dependency fix is less about the go get than about the judgement around it: which findings are reachable, which module has no fixed version and needs a fork, which upgrade drags in an unrelated major, and whether the toolchain in CI is itself the problem. The agent does that reading in its own sandbox with the real toolchain and the real report, and writes down each decision next to the finding it answers.

Nothing has to be trusted from a summary. The two govulncheck reports, the module changes, the build and the race-enabled tests are in the run's record and pasted into the pull request, so review is a comparison, not a reconstruction. Several Go services can be audited at once, each in its own sandbox.

Frequently asked questions

Why not just run go get -u ./... and be done?

Because it would move every direct dependency, including GORM and Echo, and this repository is on GORM v1, whose successor has a different import path and API. The agent upgrades only what a finding names and leaves majors for their own pull request.

Is swapping jwt-go for golang-jwt safe for tokens already issued?

Yes. The fork started from the same code and keeps HS256, MapClaims and Parse, so a token signed with the old module verifies with the new one and the same secret. The handler tests that log in and call protected routes exercise exactly that path.

What if govulncheck says a finding is not reachable?

The agent still records it, and for a module with a fixed version it usually takes the bump anyway because it is cheap. For jwt-go there is no fixed version at all, which is why the move to the fork is the fix regardless of reachability.

Does raising the Go version change how the app behaves?

The code itself is unchanged, but the standard library it compiles against gets every HTTP and TLS fix since 1.18, which is the point. The pull request names the exact version it used so the reviewer can match it to their build images.

More Echo jobs

The same job on other stacks

Keep reading