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

chore: add csrf token handling #289

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tsaleksandrova
Copy link
Contributor

No description provided.

}).then(function () {
request.authenticate(new CsrfAuthenticator({
csrfFetchUrl: restServiceMockUrl + '/form'
})).then(function () {
request.post(restServiceMockUrl + '/form').send({
Copy link
Contributor

Choose a reason for hiding this comment

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

subsequent calls should be scheduled on the flow, no need to calling in promise resolve callback

request.post(restServiceMockUrl + '/form').send({
field: 'value'
}).do().then(function (res) {
expect(res.status).toBe(200);
}).catch(function (err) {
}).catch(function () {
Copy link
Contributor

@maximnaidenov maximnaidenov Mar 2, 2021

Choose a reason for hiding this comment

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

unhandled promise rejection will fail the test, no need for explicit assertion


var CSRF_HEADER = 'x-csrf-token';

function CsrfAuthenticator(options){
Copy link
Contributor

Choose a reason for hiding this comment

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

I am also fine with declarative setup like request.authenticate({crsf: {user,pass,url})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is no user or pass that could be associated with csrf

Copy link
Contributor

Choose a reason for hiding this comment

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

There is for sure, the call for getting the crsf token should be authenticated, see the reference impl: https://github.wdf.sap.corp/I533952/uiveri5_iscoper/blob/9f08dcbbf05b692184aa619266ea1b3904ad8e61/iscoperPlugin.js#L43

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for this link but as you know I've had it for 2 months and looked at it every day since.
please read a bit more about csrf, bearer tokens and relaystate param (as it also came up) and that they are not the same e.g.
https://owasp.org/www-community/attacks/csrf
https://portswigger.net/web-security/csrf/tokens
https://portswigger.net/web-security/csrf
https://blogs.sap.com/2019/02/19/what-is-relaystate-in-saml-and-how-to-configure-relaystate-on-as-abap/
https://stackoverflow.com/questions/25838183/what-is-the-oauth-2-0-bearer-token-exactly/25843058

if you want to add support for authentication, it would be a separate topic. besides, user:auth in the url is accepted https://visionmedia.github.io/superagent/#authentication


module.exports = function() {
var app = express();
// will also use a _csrf cookie (secret) and validate against it
var csrfProtection = csrf({
Copy link
Contributor

Choose a reason for hiding this comment

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

good idea to use standard module

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what is the standard module?

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