# Cross-Site Request Forgery (CSRF) (CWE-352) The web application does not, or can not, sufficiently verify whether a well-formed, valid, consistent request was intentionally provided by the user who submitted the request. **Stack:** Go - Prevalence: Media 3 lenguajes cubiertos - Impact: Alto 3 reglas de severidad alta - Prevention: Documentada 3 ejemplos de corrección **OWASP:** Broken Access Control (A01:2021-Broken Access Control) - #1 ## Description When a web server is designed to receive a request from a client without any mechanism for verifying that it was intentionally sent, then it might be possible for an attacker to trick a client into making an unintentional request to the web server which will be treated as an authentic request. ## Prevention Estrategias de prevención para Cross-Site Request Forgery basadas en 1 reglas de detección de Shoulder. ### Go Add CSRF middleware to protect state-changing endpoints ## Warning Signs - [HIGH] State-changing endpoints lack CSRF protection ## Consequences - Modificar datos de la aplicación - Obtener privilegios - Ejecutar código no autorizado ## Mitigations - Usa tokens anti-CSRF en todas las solicitudes que cambien estado - Comprueba la cabecera Referer - Usa el atributo SameSite en las cookies ## Detection - Total rules: 3 - Languages: javascript, typescript, python, go ## Rules by Language ### Go (1 rules) - **Missing CSRF Protection (Gin)** [HIGH]: State-changing endpoints lack CSRF token protection. - Remediation: Add CSRF middleware using gin-csrf. ```go import "github.com/utrack/gin-csrf" r := gin.Default() r.Use(csrf.Middleware(csrf.Options{ Secret: os.Getenv("CSRF_SECRET"), })) r.POST("/transfer", transferHandler) ``` Learn more: https://shoulder.dev/learn/go/cwe-352/csrf-protection