github.com/gorilla/csrf
go
pkg:golang/github.com/gorilla/csrf
77 Dependabot PRs
5 months ago
49 repositories
0 repositories
Security Advisories
github.com/gorilla/csrf improperly validates TrustedOrigins allowing CSRF attacks
gorilla/csrf CSRF vulnerability due to broken Referer validation
Recent PRs (filtered by: Open )
chore(deps): bump github.com/gorilla/csrf from 1.7.1 to 1.7.3
build(deps): bump the backend group across 1 directory with 24 updates
Rose2161/hub #356
chore(deps): bump github.com/gorilla/csrf from 1.7.2 to 1.7.3
Bump the go_modules group with 5 updates
H1d3r/sliver #296
Bump the go_modules group across 2 directories with 15 updates
build(deps): bump the backend group across 1 directory with 23 updates
Rose2161/hub #349
chore(deps): bump github.com/gorilla/csrf from 1.7.0 to 1.7.3
Reality2byte/eth2-beaconchain-explorer #6
Bump the go_modules group across 1 directory with 4 updates
chore(deps): bump the go_modules group across 1 directory with 2 updates
Bump the go_modules group across 5 directories with 5 updates
Cringely/docker-alpine-nfs-server #12
Bump github.com/gorilla/csrf from 1.7.1 to 1.7.3
Mr-Ao-Dragon/cashier-readme #5
Bump the go_modules group across 1 directory with 10 updates
H1d3r/headscale #239
chore(deps): bump the go_modules group across 1 directory with 3 updates
chore(deps): bump github.com/gorilla/csrf from 1.7.2 to 1.7.3 in /src
groq/harbor #5
Bump github.com/gorilla/csrf from 1.7.3-0.20250123201450-9dd6af1f6d30 to 1.7.3 in /test in the go_modules group across 1 directory
saytyarnorngloreia/sing-box #2
Bump the go_modules group across 1 directory with 7 updates
Bump github.com/gorilla/csrf from 1.7.2 to 1.7.3
Bump the go_modules group across 1 directory with 2 updates
chore(deps): bump the go_modules group across 1 directory with 8 updates
Silvrbckw/eth2-beaconchain-explorer #2
chore(deps): bump github.com/gorilla/csrf from 1.7.1 to 1.7.3
build(deps): bump the go_modules group across 5 directories with 4 updates
Bump the go_modules group across 2 directories with 4 updates
Bump the backend group across 1 directory with 12 updates
artifacthub/hub #4419
dev: bump the safe group across 1 directory with 30 updates
TheThingsNetwork/lorawan-stack #7642
build(deps): bump the backend group with 20 updates
Rose2161/hub #330
dev: bump the safe group across 1 directory with 17 updates
TheThingsNetwork/lorawan-stack #7627
Bump the backend group across 1 directory with 9 updates
artifacthub/hub #4395
build(deps): bump the go_modules group across 5 directories with 3 updates
Bump github.com/gorilla/csrf from 1.7.1 to 1.7.3
dmwm/dbs2go #143
Bump the backend group across 1 directory with 8 updates
artifacthub/hub #4393
dev: bump the safe group across 1 directory with 15 updates
TheThingsNetwork/lorawan-stack #7616
Bump the backend group across 1 directory with 5 updates
artifacthub/hub #4382
Bump github.com/gorilla/csrf from 1.7.2 to 1.7.3
chore(deps): bump github.com/gorilla/csrf from 1.7.2 to 1.7.3 in /src
goharbor/harbor #21877
Bump github.com/gorilla/csrf from 1.7.3-0.20250123201450-9dd6af1f6d30 to 1.7.3
getlantern/lantern-server-manager #2
Bump github.com/gorilla/csrf from 1.7.2 to 1.7.3
Azure/ARO-RP #4188
Bump github.com/gorilla/csrf from 1.7.2 to 1.7.3
Package Details
| Name: | github.com/gorilla/csrf |
| Ecosystem: | go |
| PURL Type: | golang |
| Package URL: | pkg:golang/github.com/gorilla/csrf |
| JSON API: | View JSON |
Security Advisories
Package Information
Package csrf (gorilla/csrf) provides Cross Site Request Forgery (CSRF) prevention middleware for Go web applications & services. It includes: * The `csrf.Protect` middleware/handler provides CSRF protection on routes attached to a router or a sub-router. * A `csrf.Token` function that provides the token to pass into your response, whether that be a HTML form or a JSON response body. * ... and a `csrf.TemplateField` helper that you can pass into your `html/template` templates to replace a `{{ .csrfField }}` template tag with a hidden input field. gorilla/csrf is easy to use: add the middleware to individual handlers with the below: ... and then collect the token with `csrf.Token(r)` before passing it to the template, JSON body or HTTP header (you pick!). gorilla/csrf inspects the form body (first) and HTTP headers (second) on subsequent POST/PUT/PATCH/DELETE/etc. requests for the token. Note that the authentication key passed to `csrf.Protect([]byte(key))` should be 32-bytes long and persist across application restarts. Generating a random key won't allow you to authenticate existing cookies and will break your CSRF validation. Here's the common use-case: HTML forms you want to provide CSRF protection for, in order to protect malicious POST requests being made: Note that the CSRF middleware will (by necessity) consume the request body if the token is passed via POST form values. If you need to consume this in your handler, insert your own middleware earlier in the chain to capture the request body. You can also send the CSRF token in the response header. This approach is useful if you're using a front-end JavaScript framework like Ember or Angular, or are providing a JSON API: If you're writing a client that's supposed to mimic browser behavior, make sure to send back the CSRF cookie (the default name is _gorilla_csrf, but this can be changed with the CookieName Option) along with either the X-CSRF-Token header or the gorilla.csrf.Token form field. In addition: getting CSRF protection right is important, so here's some background: * This library generates unique-per-request (masked) tokens as a mitigation against the BREACH attack (http://breachattack.com/). * The 'base' (unmasked) token is stored in the session, which means that multiple browser tabs won't cause a user problems as their per-request token is compared with the base token. * Operates on a "whitelist only" approach where safe (non-mutating) HTTP methods (GET, HEAD, OPTIONS, TRACE) are the *only* methods where token validation is not enforced. * The design is based on the battle-tested Django (https://docs.djangoproject.com/en/1.8/ref/csrf/) and Ruby on Rails (http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html) approaches. * Cookies are authenticated and based on the securecookie (https://github.com/gorilla/securecookie) library. They're also Secure (issued over HTTPS only) and are HttpOnly by default, because sane defaults are important. * Go's `crypto/rand` library is used to generate the 32 byte (256 bit) tokens and the one-time-pad used for masking them. This library does not seek to be adventurous.
| Repository: | https://github.com/gorilla/csrf |
| Homepage: | https://github.com/gorilla/csrf |
| Latest Release: |
v1.7.3
over 1 year ago |
| Dependent Repos: | 2,067 |
| Dependent Packages: | 384 |
| Ranking: | Top 0.1807% by dependent repos Top 0.2079% by dependent pkgs |