{"repo":"justinas/nosurf","free":true,"listed":false,"github":"https://github.com/justinas/nosurf","clone":"git clone https://github.com/justinas/nosurf.git","description":"CSRF protection middleware for Go.","language":"Go","stars":1746,"topics":["csrf","go","security","middleware"],"license":"MIT","category":"security-tools","readme_excerpt":"nosurf nosurf is an HTTP package for Go that helps you prevent Cross-Site Request Forgery attacks. It acts like a middleware and therefore is compatible with basically any Go HTTP application. Why? Even though CSRF is a prominent vulnerability, Go's web-related package infrastructure mostly consists of micro-frameworks that neither do implement CSRF checks, nor should they. nosurf solves this problem by providing a CSRFHandler that wraps your http.Handler and checks for CSRF attacks on every non-safe (non-GET/HEAD/OPTIONS/TRACE) method. nosurf requires Go 1.1 or later. Features Supports any http.Handler (frameworks, your own handlers, etc.) and acts like one itself. Allows exempting specific endpoints from CSRF checks by an exact URL, a glob, or a regular expression. Allows specifying your own failure handler. Want to present the hacker with an ASCII middle finger instead of the plain old HTTP 400 ? No problem. Uses masked tokens to mitigate the BREACH attack. Has no dependencies outside the Go standard library. Example Manual token verification In some cases the CSRF token may be send through a non standard way, e.g. a body or request is a JSON encoded message with one of the fields being a token. In such case the handler(path) should be excluded from an automatic verification by using one of the exemption methods: Later on, the token must be verified by manually getting the token from the cookie and providing the token sent in body through: VerifyToken(tkn, tkn2 string) boo","default_branch":null,"files":null,"tree":[],"storefront":"/r/justinas","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/justinas/nosurf/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}