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

XSRF plugin for Angular #207

Merged
merged 10 commits into from Oct 19, 2020
Merged

XSRF plugin for Angular #207

merged 10 commits into from Oct 19, 2020

Conversation

maramihali
Copy link

@maramihali maramihali commented Oct 14, 2020

Fixes #194

Created a separate plugin that provides protection against XSRF in Angular. More details can be found here: https://docs.angularjs.org/api/ng/service/$http#cross-site-request-forgery-xsrf-protection

Changed the directory tree to include the two XSRF plugins in the same directory with the functionality used by both placed in a separate file.

@maramihali maramihali added enhancement New feature or request plugin labels Oct 14, 2020
@maramihali maramihali self-assigned this Oct 14, 2020
safehttp/plugins/angular_xsrf/angular_xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/angular_xsrf/angular_xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/angular_xsrf/angular_xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/angular_xsrf/angular_xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/angular_xsrf/angular_xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/angular_xsrf/angular_xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/angular_xsrf/angular_xsrf.go Outdated Show resolved Hide resolved
Comment on lines 117 to 121
wantHeader: map[string][]string{
"Content-Type": {"text/plain; charset=utf-8"},
"X-Content-Type-Options": {"nosniff"},
},
wantBody: "Forbidden\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions feel like we are testing the framework rather than just the plugin. I would personally just test for status here. If you want to be thorough maybe also body, but the header check I think should only be a "I added a cookie or not", which would allow you to merge this test with the one above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but we tested for the headers everywhere and I mostly did it for uniformity across tests. I suggest removing these checks, if you think they are not needed, in a follow-up PR.

@maramihali maramihali added the hacktoberfest-accepted temporary, just for hacktoberfest eligible PRs label Oct 14, 2020
@kele kele changed the title Created a XSRF plugin for Angular XSRF plugin for Angular Oct 14, 2020
Copy link
Collaborator

@kele kele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the non-Angular files just moved? If yes, have you used git mv to indicate that?

safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Show resolved Hide resolved
Mara Mihali added 2 commits October 15, 2020 12:21
…ne and created file that contains helper functions used by both. Refactored some logic according to code review
@maramihali
Copy link
Author

It seemed that it correctly moved everything besides one file (because we kept safehttp/plugins/xsrf/xsrf.go for functionality shared by both versions).

…enCookieName and TokenHeaderName to their default values as indicated by the documentation
safehttp/plugins/xsrf/html/xsrf.go Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf_test.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf_test.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf_test.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/html/doc.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/html/xsrf.go Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/html/xsrf.go Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf_test.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf_test.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf_test.go Show resolved Hide resolved
@maramihali maramihali requested a review from kele October 16, 2020 10:04
safehttp/plugins/xsrf/angular/xsrf_test.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf_test.go Outdated Show resolved Hide resolved
@maramihali maramihali requested a review from kele October 16, 2020 14:03
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/angular/xsrf.go Outdated Show resolved Hide resolved
safehttp/plugins/xsrf/html/xsrf.go Show resolved Hide resolved
safehttp/plugins/xsrf/html/xsrf.go Show resolved Hide resolved
@empijei empijei merged commit 0f92e44 into master Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest-accepted temporary, just for hacktoberfest eligible PRs plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend the XSRF plugin to provide protection for Angular XHR
3 participants