anantbhandarkar/make-it-right/mir-backend-go-echo

Claude Code and agent skill by anantbhandarkar/make-it-right

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Make It Right (Echo module). Echo web framework reliability augmentation for Go backends, covering Echo v5 (current) and v4 (maintained). Chains: mir-backend (generic gates) -> mir-backend-go (Go runtime) -> this (Echo library mechanics). Adds the mechanical footguns the runtime-agnostic tiers omit: echo.Context comes from a sync.Pool and must never be retained past the handler or handed to a goroutine; the v4->v5 rewrite that AI mixes up (Context became a *echo.Context struct, Logger became *slog.Logger, HTTPErrorHandler's arguments swapped, e.Shutdown and e.Close removed in favour of StartConfig); Bind never validates, so a missing c.Validate ships unchecked input, and Bind merges path and query values into one struct, a mass-assignment path; middleware ordering and graceful shutdown; and Echo's insecure defaults - c.RealIP() trusts X-Forwarded-For unless IPExtractor is set, and middleware.Secure sends no HSTS or CSP. TRIGGER only when the Go backend uses the Echo framework - building, reviewing, or debugging an Echo handler, middleware, or router. SKIP for Gin (mir-backend-go-gin), Fiber (mir-backend-go-fiber), chi, stdlib net/http, or any non-Echo stack, and for every non-Go runtime.

Install

npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-go-echo

SKILL.md

The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-go-echo.

/mir-backend-go-echo · Make It Right (Echo)

Bottom tier of the chain: mir-backend (generic gates) → mir-backend-go (Go runtime model) → this (Echo library mechanics). Run the gates first; load the Go runtime tier for goroutine lifecycle, context propagation, and race discipline; reach for this at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. Runtime-level concerns (goroutine leaks, data races, context propagation, typed-nil, slice aliasing, `os.Root`, module checksums) live in `mir-backend-go` — not here.

Stack state, verified 13 Aug 2026.

LineCurrentNotes
v5 (github.com/labstack/echo/v5)v5.3.1 (2026-07-21); v5.0.0 GA 2026-01-18Current major. go.mod requires Go 1.25
v4 (github.com/labstack/echo/v4)v4.15.4 (2026-06-15)Still receiving security and bug fixes

Establish the major before writing a line. Handler signatures, the logger, the error handler, and the whole server-startup API changed in v5 (footgun 2). Note also that echo-contrib ships separate release lines for v4 and v5 — importing the wrong one gives type errors that look like Echo's fault. Whichever major you are on, this module's earlier claim that "v5 is pre-release" is obsolete: v5 has been GA since January 2026.

The Echo footguns AI walks into most

1. echo.Context is pooled — do not retain it across the handler boundary

Echo keeps contexts in a sync.Pool and reuses them. Storing the context in a struct, or handing it to a goroutine that outlives the handler, means you are reading a context that now belongs to a different request.

go
// WRONG: c is recycled after the handler returns
func handler(c *echo.Context) error {
go func() {
sendNotification(c.Param("id"), c.Request().Header.Get("X-Trace-Id"))
}()
return c.NoContent(http.StatusAccepted)
}
// RIGHT: capture values and detach the context before spawning
func handler(c *echo.Context) error {
id := c.Param("id")
traceID := c.Request().Header.Get("X-Trace-Id")
ctx := context.WithoutCancel(c.Request().Context()) // keeps values, drops cancellation
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
go func() { defer cancel(); sendNotification(ctx, id, traceID) }()
return c.NoContent(http.StatusAccepted)
}
  • c.Request().Context() is canceled the instant the handler returns. Passing it to background work makes every downstream call fail with context canceled — this is the more common bug than the pooling itself, because it fails loudly on the first request rather than silently under load.
  • Values stashed with c.Set(key, value) live in the per-request store. Read them out before the handler returns if a goroutine needs them.
  • Copy the values you need into a plain struct. Do not build a helper that "clones the context" — there is no supported clone, and the pooled fields will still be reused.
2. v4 and v5 are different APIs — do not mix them
Concernv4v5
Handler signaturefunc(c echo.Context) error (interface)func(c *echo.Context) error (struct pointer)
Loggercustom echo.Logger interface; e.Logger.Error(...)*slog.Logger; c.Logger() returns *slog.Logger
Error handlerfunc(err error, c echo.Context)func(c *echo.Context, err error) — arguments swapped
Default error handlere.DefaultHTTPErrorHandlerDefaultHTTPErrorHandler(exposeError bool) factory
Binder interfaceBind(i any, c Context) errorBind(c *Context, target any) error
Standalone binders—BindBody, BindQueryParams, BindPathValues (was BindPathParams), BindHeaders
Server startupe.Start / e.StartTLS / e.Shutdown / e.Close; e.Server is an exported *http.ServerStartConfig{...}.Start(ctx, e); `e.Shutdown` and `e.Close` are gone; the http.Server is internal, reachable only via StartConfig.BeforeServeFunc
c.RealIP() defaulttrusts X-Forwarded-For / X-Real-IPtrusts them in v5.0.0; returns the socket peer address from v5.1.0
Removed—GetPath, the MethodNotAllowedHandler / NotFoundHandler package variables

The swapped HTTPErrorHandler arguments are the nastiest: both parameters are single-word types, so a v4 handler pasted into a v5 project can compile in some shapes and log the wrong thing.

3. Bind does not validate — and Bind reads more sources than you think

c.Bind(&req) deserializes; it never runs validation tags. Two separate mistakes follow.

Forgetting `Validate` is the silent one. Registering no validator is loud — c.Validate(x) returns ErrValidatorNotRegistered. Never calling Validate at all produces no error anywhere, and your validate:"required,email" tags are decoration.

go
type customValidator struct{ v *validator.Validate }
func (cv *customValidator) Validate(i any) error { return cv.v.Struct(i) }
e := echo.New()
e.Validator = &customValidator{v: validator.New()}
go
var req CreateOrderRequest
if err := c.Bind(&req); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid request")
}
if err := c.Validate(&req); err != nil { // this line is the one that gets dropped
return echo.NewHTTPError(http.StatusUnprocessableEntity, "validation failed")
}

`Bind` merges sources. Echo's default binder fills the struct from path parameters and, for methods without a body (GET, DELETE, HEAD), from query parameters — as well as from the body. A field an attacker cannot reach through JSON may be settable through the URL. When you want exactly one source, use the explicit binders (echo.BindBody(c, &req), echo.BindQueryParams(c, &req) in v5; (&echo.DefaultBinder{}).BindBody(c, &req) in v4) instead of the catch-all Bind.

  • Never bind to your DB/ORM model. Use a dedicated request struct per endpoint. See Security, mass assignment.
  • validate:"required" rejects the zero value, not just an absent key — use a pointer field when 0 or "" is legitimate.
4. Middleware order — Recover() first, and know Pre from Use

Echo runs middleware in registration order. Your middleware registered before middleware.Recover() is not covered by it, and a panic there kills the process.

go
e := echo.New()
e.Pre(middleware.RemoveTrailingSlash()) // runs BEFORE routing — can rewrite the path
e.Use(middleware.Recover()) // runs after routing; register it first among Use
e.Use(middleware.RequestID())
e.Use(authMiddleware())
  • e.Pre(...) runs before the router matches, so it is the only place a middleware can change the path that routing sees. e.Use(...) runs after the match.
  • Anything in Pre that rewrites or unescapes the path can desynchronise routing from later path handling — that is exactly the shape of CVE-2026-55677 (see Security). Add path-rewriting middleware deliberately, never by copy-paste.
  • Group middleware applies to routes registered on that group after the Use call. Register middleware first, routes second.
  • Recover() covers panics on the request goroutine only. Goroutines you spawn need their own recover — mir-backend-go footgun 5.
5. HTTPErrorHandler — one error shape, and do not expose the error

Returning raw Go errors from handlers produces a different response shape per endpoint and leaks internals. Echo's default (DefaultHTTPErrorHandler(false)) returns {"message": "<status text>"}; the factory's exposeError argument adds {"error": "<err.Error()>"} to the body — that is direct internal-error disclosure, and it must stay false outside development.

go
// v5 signature: (c, err)
e.HTTPErrorHandler = func(c *echo.Context, err error) {
var he *echo.HTTPError
if errors.As(err, &he) {
_ = c.JSON(he.Code, map[string]any{"error": he.Message})
return
}
c.Logger().Error("unhandled error", "err", err, "path", c.Path()) // log detail
_ = c.JSON(http.StatusInternalServerError, map[string]any{"error": "internal server error"})
}
  • Return echo.NewHTTPError(code, message) from handlers and middleware; let the error handler shape the response.
  • The error handler does nothing if the response is already committed. A handler that writes a 200 and then returns an error sends a 200 with a success body — check errors before you write.
  • The default handler does not log. If you replace it, logging is now your job; if you keep it, add a logging middleware or errors vanish.
6. Graceful shutdown — different in each major

v5: e.Start(":8080") already installs a SIGINT/SIGTERM handler and drains with a default GracefulTimeout of 10 seconds. e.Shutdown and e.Close no longer exist. To tune it, drive StartConfig yourself:

go
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
sc := echo.StartConfig{
Address: ":8080",
GracefulTimeout: 30 * time.Second,
OnShutdownError: func(err error) { slog.Error("drain exceeded timeout", "err", err) },
BeforeServeFunc: func(s *http.Server) error { // the only hook to the http.Server in v5
s.ReadHeaderTimeout = 5 * time.Second
s.IdleTimeout = 60 * time.Second
return nil
},
}
if err := sc.Start(ctx, e); err != nil && !errors.Is(err, http.ErrServerClosed) {
slog.Error("server failed", "err", err)
}

A negative GracefulTimeout disables draining entirely — do not set it to skip a slow shutdown; fix the slow request instead.

v4: wire it manually, and set the timeouts, because e.Server is a zero-value *http.Server with none:

go
e.Server.ReadHeaderTimeout = 5 * time.Second
e.Server.ReadTimeout = 15 * time.Second
e.Server.WriteTimeout = 30 * time.Second
go func() {
if err := e.Start(":8080"); err != nil && !errors.Is(err, http.ErrServerClosed) { /* ... */ }
}()
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
<-ctx.Done()
shutdownCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
_ = e.Shutdown(shutdownCtx)

In both majors, Shutdown does not wait for goroutines you spawned inside handlers — track them yourself. Close DB pools after the drain returns.

Security

Echo-specific mechanics. Runtime-level items (os.Root, SSRF dialer control, govulncheck, module checksums, secret redaction) are in mir-backend-go.

CVE-2026-55677 — encoded %2F bypassed route-level middleware

The router matched on the raw encoded path while StaticDirectoryHandler unescaped %2F to / before resolving the file. A request could therefore be routed as if it were a public path while the file handler read a protected one, bypassing auth middleware attached to a route prefix. High severity, CVSS 7.5.

AffectedFixed
v4 ≤ 4.15.24.15.3
v5 ≤ 5.1.15.2.0

The fix disables path unescaping in static file serving by default. That means:

  • middleware.StaticConfig.EnablePathUnescaping = true re-opens the exact mismatch the fix closed. Turn it on only if you genuinely serve files whose names contain encoded characters, and only if no middleware makes authorization decisions from the path. DisablePathUnescaping is deprecated and now ignored.
  • The router's RouterConfig.UnescapePathParamValues is the same class of decision for path parameters.
  • The pattern to recognise: e.StaticFS("/", os.DirFS("public")) next to route-prefix auth middleware. Authorize on the resource, not on the string in the URL.

GHSA-pgvm-wxw2-hrv9 (Feb 2026) is the sibling bug: Windows path traversal via backslash in middleware.Static's default filesystem. Serve from an explicit fs.FS (os.DirFS, embed.FS) rather than the default root-path filesystem, and keep Browse: false so directories are not listed.

c.RealIP() trusts client headers on v4 and on v5.0.0

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
15
7-day trend score
14

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/anantbhandarkar/make-it-right/mir-backend-go-echo/badge)](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-go-echo)

Something wrong with this skill or its page? Tell us.