What the agent does
The agent reads how the service answers before deciding which headers fit, because an API that serves only JSON and an API that also hosts Swagger UI need different policies. In an Echo app like xesina/golang-echo-realworld-example-app, go.mod declares go 1.18 with github.com/labstack/echo/v4 v4.1.16, github.com/jinzhu/gorm with SQLite, github.com/dgrijalva/jwt-go and github.com/swaggo/echo-swagger. router/router.go builds the instance: RemoveTrailingSlash as a pre-middleware, middleware.Logger(), a CORSWithConfig that allows every origin with the Authorization header, and a go-playground validator. main.go mounts echoSwagger.WrapHandler on /swagger/*, registers the Conduit routes from handler/routes.go under /api, and listens on 127.0.0.1:8585. The handler tests in handler/*_test.go call h.SignUp(c) and friends on a context from e.NewContext, so they never pass through middleware. .github/workflows/go.yml runs go build -v ./... and go test -v ./... on Go 1.18.
Echo v4 ships the middleware, so go.mod does not change. The agent registers middleware.SecureWithConfig in router.New() after the logger, with ContentTypeNosniff: "nosniff", XFrameOptions: "DENY", XSSProtection: "0" instead of the version's default 1; mode=block, which modern browsers ignore or misuse, ReferrerPolicy: "no-referrer", HSTSMaxAge set to one year with subdomains included, and a ContentSecurityPolicy for a JSON API: default-src 'none'; frame-ancestors 'none'. That policy is correct for every /api route, where no browser executes anything, and wrong for /swagger/index.html, which is a page with scripts, styles and a fetch to /swagger/doc.json. Rather than loosen the whole service, the agent gives the config a Skipper for paths under /swagger/ and registers a second SecureWithConfig on that group whose policy allows 'self' for scripts, styles, images and connections plus 'unsafe-inline' for the inline bootstrap script Swagger UI's page carries; the pull request says this is the one place inline is allowed and why.
Strict-Transport-Security in this version is sent when c.IsTLS() is true or when the request carries X-Forwarded-Proto: https, with no trusted-proxy list, and the server listens on plain HTTP on the loopback address. The agent leaves the condition as the framework has it and documents in readme.md that the header appears only behind a TLS-terminating proxy that sets the forwarded header, so an operator checking with curl -I http://127.0.0.1:8585/api/tags is not surprised by its absence. The permissive CORS config is left as it is, since changing which origins may call the API is a product decision, but the pull request names it as the next thing to tighten.
The handler tests cannot prove any of this, so the agent adds router/router_test.go, which calls router.New(), registers a throwaway GET /ping and a GET /swagger/ping, sends requests through e.ServeHTTP so the middleware runs, and asserts the policy, X-Frame-Options, nosniff, X-XSS-Protection: 0 and Referrer-Policy on the API path, the looser policy on the Swagger path, and that Strict-Transport-Security is present only when the request carries X-Forwarded-Proto: https. In the sandbox it runs go build ./... and go test -v ./... as the workflow does, starts the server, runs curl -I on /api/tags and /swagger/index.html, and opens the Swagger page in the sandbox's browser to confirm the UI renders and lists the Conduit operations with no policy violation in the console before opening the pull request.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Add security headers to this Echo v4 API. Read go.mod, main.go, router/router.go, handler/routes.go, one of the handler tests, Makefile, Dockerfile and .github/workflows/go.yml first. In router.New register middleware.SecureWithConfig after the logger with ContentTypeNosniff nosniff, XFrameOptions DENY, XSSProtection 0, ReferrerPolicy no-referrer, HSTSMaxAge one year including subdomains, and ContentSecurityPolicy default-src 'none'; frame-ancestors 'none', skipped for paths under /swagger/. Give the /swagger/ routes their own SecureWithConfig whose policy allows self for scripts, styles, images and connect plus unsafe-inline for the page's inline script, and explain in the pull request why that is the only inline allowance. Do not change the CORS config, but name it in the pull request as the next thing to tighten. Add router/router_test.go that registers throwaway routes, sends requests through e.ServeHTTP and asserts every header on an API path and on a swagger path, and that HSTS is sent only with X-Forwarded-Proto https. Note in readme.md when HSTS appears. Run go build ./... and go test -v ./..., start the server, curl -I /api/tags and /swagger/index.html, open the Swagger page in the browser and confirm it renders without policy violations, then open a pull request that pastes the curl output.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- 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.
- 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.
- 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
What comes back is a pull request that changes router/router.go and main.go, adds router/router_test.go and adds a paragraph to readme.md. The description pastes curl -I for /api/tags, showing Content-Security-Policy: default-src 'none'; frame-ancestors 'none', X-Frame-Options: DENY, X-Content-Type-Options: nosniff, X-XSS-Protection: 0 and Referrer-Policy: no-referrer, and for /swagger/index.html, showing the looser policy, with a screenshot of Swagger UI rendered under it and an empty console.
The run's record holds go build, the full go test -v ./... output including the existing handler tests against the SQLite test database, the curl runs and the browser session. go.mod and go.sum are untouched because the middleware is part of Echo.
Before merging, a reviewer decides whether Swagger UI should ship in production at all, in which case the second policy can go, whether to replace the inline allowance with a hash of the page's script, and which origins the CORS config should allow now that the rest is tightened. The existing go.yml workflow runs the new test on push.
Run it on every new Echo service
A team with several Echo services starts one run per repository from its own server: one POST /o/{org}/sessions each, with that repository in resources and a request_id that is a UUID v5 of the repository's full name, so a retried call returns the run already started instead of a second pull request. Each run reads what that service serves, so a pure JSON API gets default-src 'none' everywhere and a service with server-rendered templates gets a policy written from its templates.
Afterwards, an automation on the Project with a github trigger on pull_request.opened and pull_request.synchronize and the prompt "if this pull request adds a route that serves HTML or static files, check that the Secure middleware's policy for that path allows what the page loads and comment with the directive it needs" keeps new pages from shipping blank under the API policy. The trigger adds the pull request after the prompt; only work by an owner, member or collaborator fires it, never a fork's.
The use case this job follows, with its automation and trigger: Hand off a long task.
Why run it on Rush?
The failure mode of this job is quiet: the API keeps answering JSON under a strict policy and nobody notices until the Swagger page, or a status page added later, renders blank. The agent runs the service in its own sandbox, sends requests through the real middleware chain in a test, and opens the one HTML page the service has in a real browser, so the policy is checked where it bites.
The sandbox keeps the build, the test output, the curl headers and the browser session with the run, and the pull request cites them. A team with many Go services gets one run and one pull request per service, each with headers derived from what that service actually serves.
Frequently asked questions
Why two policies instead of one looser one?
Because default-src 'none' is the right policy for every /api route, where nothing executes, and it would break /swagger/index.html, which loads scripts and styles and fetches doc.json. A Skipper on the strict config and a second SecureWithConfig on the Swagger group give each path the tightest policy it can carry. The test asserts both so a later refactor cannot swap them.
Why is X-XSS-Protection set to 0 rather than left at the default?
This Echo version's default is 1; mode=block, which turns on a legacy filter that current browsers have removed and that older ones could abuse to leak data. Setting it to 0 tells the remaining browsers to leave the filter off; the Content Security Policy is what does the real work. The pull request says this so the change does not read as a downgrade.
Why does curl on 127.0.0.1 show no HSTS header?
In this Echo version the header is sent only when the connection is TLS or the request carries X-Forwarded-Proto: https, and the server listens on plain HTTP. Behind a TLS-terminating proxy that sets the forwarded header it appears; the readme paragraph and the router test both spell that out.
Does this change CORS?
No. router.go allows every origin today, and which origins should call the API is a decision the reviewer owns. The pull request names it as the next change, with the AllowOrigins line to edit, rather than guessing a list.
Why do the existing handler tests not cover this?
They build a context with e.NewContext and call the handler function directly, which skips the middleware chain entirely. The new router_test.go sends requests through e.ServeHTTP, so the Secure middleware runs exactly as it does for a real request.