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 utilities to prevent cookie tossing and replay attacks #2

Merged
merged 22 commits into from
May 4, 2021

Conversation

mcollina
Copy link
Member

@mcollina mcollina commented May 3, 2021

Checklist

@mcollina mcollina requested a review from jsumners May 3, 2021 14:18
@zekth
Copy link
Member

zekth commented May 3, 2021

Note: on another PR we might need to adress the move from var to let/const

index.js Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
@@ -131,15 +174,50 @@ Tokens.prototype.verify = function verify (secret, token) {
}

var index = token.indexOf('-')
Copy link
Member

Choose a reason for hiding this comment

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

Maybe in another PR, but wouldn't it be clearer to var tokenParts = token.split('-')?

Copy link
Member Author

Choose a reason for hiding this comment

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

possibly, I would like to ship this and the linked change in fastify-csrf first.

index.js Outdated Show resolved Hide resolved
index.js Outdated
Comment on lines 71 to 77
var validity = Number.isInteger(opts.validity) === true
? opts.validity
: 0

if (typeof validity !== 'number' || !isFinite(validity) || validity < 0) {
throw new TypeError('option validity must be finite number > 0')
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this if (typeof... become redundant by the Number.isInteger, don't you?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the code is wrong right now. We are casting strings to zero instead of throwing. The code was correct as it was before.

Copy link
Member

Choose a reason for hiding this comment

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

Please explain. Number.isInteger only returns true for integer primitives.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah, it's the word "cast" that is confusing me. No casting is taking place; if a string is supplied then it is ignored and the default value, 0, is used instead.

When I left my change suggestion I had not reached the if (typeof ... yet. I saw the possibility of a non-integer being supplied for the option and suggested an easy change to ignore such cases.

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

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

LGTM

@mcollina mcollina merged commit 5882472 into master May 4, 2021
@mcollina mcollina deleted the extended-token branch May 4, 2021 15:00
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.

3 participants