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

add csrf filter middleware #89

Merged
merged 2 commits into from
Mar 2, 2018
Merged

Conversation

niklasf
Copy link
Contributor

@niklasf niklasf commented Mar 2, 2018

Hi. Many applications need a middleware that filters cross-site requests (to prevent CSRF). Here's an attempt to implement that.

@fafhrd91
Copy link
Member

fafhrd91 commented Mar 2, 2018

looks pretty good!

I haven't done any browser related services for long time. do people use csrf tokens nowadays?

@niklasf
Copy link
Contributor Author

niklasf commented Mar 2, 2018

Yes, that's definitely an option (and OWASP still recommends using both headers and some kind of tokens). Headers alone are sufficient, though, and supported in browsers for a long time.

@fafhrd91
Copy link
Member

fafhrd91 commented Mar 2, 2018

I think csrf middleware should support tokens otherwise it's functionality is similar to cors middleware.

@niklasf
Copy link
Contributor Author

niklasf commented Mar 2, 2018

Should I perhaps try to merge this into the CORS middleware (and leave the token approach for future work)?

That would probably involve something like adding CorsBuilder::same_origin() which would be similar to CorsBuilder::allowed_origin() (but not announced in the Acess-Control-Allow-Origin header).

@fafhrd91
Copy link
Member

fafhrd91 commented Mar 2, 2018

hmm, I see. let's just merge it.

@codecov
Copy link

codecov bot commented Mar 2, 2018

Codecov Report

Merging #89 into master will decrease coverage by 0.06%.
The diff coverage is 68.51%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #89      +/-   ##
==========================================
- Coverage   78.76%   78.69%   -0.07%     
==========================================
  Files          67       68       +1     
  Lines        8085     8139      +54     
==========================================
+ Hits         6368     6405      +37     
- Misses       1717     1734      +17
Impacted Files Coverage Δ
src/middleware/mod.rs 0% <ø> (ø) ⬆️
src/middleware/csrf.rs 68.51% <68.51%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bebfc6c...e60acb7. Read the comment docs.

@fafhrd91 fafhrd91 merged commit 3a5d445 into actix:master Mar 2, 2018
@fafhrd91
Copy link
Member

fafhrd91 commented Mar 2, 2018

thanks!

@niklasf
Copy link
Contributor Author

niklasf commented Mar 2, 2018

Cool, thanks. I guess it's different enough from the CORS middleware to warrant seperation.

@fafhrd91
Copy link
Member

fafhrd91 commented Mar 2, 2018

yes, especially if we add tokens later

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

Successfully merging this pull request may close these issues.

2 participants