Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blacklist handlers rather than wrapping all and whitelist some #24

Open
peterbe opened this issue Feb 27, 2015 · 3 comments
Open

Blacklist handlers rather than wrapping all and whitelist some #24

peterbe opened this issue Feb 27, 2015 · 3 comments

Comments

@peterbe
Copy link

peterbe commented Feb 27, 2015

I have some handlers that use POST, PUT etc that I do NOT want to be protected by nosurf. These are REST API endpoints that don't need CSRF protection as you can't use them without an Auth-Token header anyway.

I can use nosurf like this:

    n := negroni.Classic()

    handler := nosurf.New(mux)
    handler.ExemptPath("/v1")
    handler.ExemptPath("/v1/bulk")
    handler.ExemptPath("/v1/flush")
    n.UseHandler(handler)
    n.Run(fmt.Sprintf(":%d", port))

But now my poor REST API endpoints get a Vary Cookie and a Set-Cookie too.

Can I use nosurf to protect just individual handler functions and now the whole mux thing?

@justinas
Copy link
Owner

Might not be the best solution, but you could give each route in your router a separate nosurf instance.

Many routers support adding subrouters, so you could have "api" and "www" sets of routes and protect only one of them.

@peterbe
Copy link
Author

peterbe commented Mar 17, 2015

Thanks. I'll try that. Do you still think it's worth keeping this issue or is grouping sub-groups of routes the solid solution?

@justinas
Copy link
Owner

It might not be an ideal solution, but I would not like to introduce much complexity for filtering routes in nosurf itself (separate blacklist/whitelist modes, etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants