Gin 1.12
Last reviewed Sep 19, 2026
Prompt Details
Prompt Composition
2prompts
- Go 1.27130 lines · 5.5K tokens
- Gin 1.1273 lines · 3.4K tokens
Total203 lines · 8.9K tokens
CWE Coverage
- 15
- 20
- 22
- 59
- 78
- 79
- 89
- 94
- 117
- 190
- 208
- 209
- 250
- 252
- 257
- 287
- 295
- 307
- 311
- 323
- 327
- 338
- 347
- 352
- 362
- 367
- 378
- 384
- 426
- 444
- 488
- 494
- 532
- 552
- 601
- 613
- 614
- 639
- 672
- 732
- 759
- 770
- 772
- 807
- 862
- 863
- 915
- 916
- 918
- 942
- 1004
- 1275
- 1395
Prompt Preview
Apply the Go 1.27 baseline first. These rules cover github.com/gin-gonic/gin v1.12.0 in the Gin 1.12 release line. Gin requires Go 1.25.0 or newer.
Routing and middleware
- Install an explicit security middleware stack;
gin.New()installs none, andgin.Default()adds onlyLoggerandRecovery, not authentication, authorization, CSRF protection, or rate limits. - Call
Engine.UseandRouterGroup.Usebefore creating protected subgroups and routes; Gin copies middleware into their handler chains at registration, so later additions do not retrofit existing routes. - Call
c.AbortWithStatusorc.AbortWithStatusJSONand immediatelyreturnon rejection.Abortstops pending handlers, not the current handler or outer middleware afterc.Next();c.Error,c.JSON, and returning from middleware alone do not abort the chain. - Read the authenticated principal with
c.Getand check presence and type before authorizing the object and tenant selected byc.Paramor bound input; typed getters returning zero values are not evidence of authentication. - Register only required methods instead of
Any, which includes CONNECT and TRACE. Apply access controls to static and administrative routes and to sensitiveNoRouteorNoMethodfallback handlers independently of protected groups. - Keep proxy, authorization, and handler path interpretation consistent when configuring
UseEscapedPath,UseRawPath,UnescapePathValues, andRemoveExtraSlash;UseEscapedPathoverridesUseRawPath. Do not decode an authorized parameter again before using it. - Enforce host