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 delay when accessing unauthorized ReST endpoints #83

Merged
merged 1 commit into from
Jun 17, 2015

Conversation

jazeee
Copy link
Contributor

@jazeee jazeee commented Jun 16, 2015

I figured I'd create this for #81, now that we are updated. I don't know what the long term solution is, but this may be a start...

EDIT: We discussed using a middleware solution. Feel free to discard this pull request...

@@ -50,7 +50,9 @@ Meteor.startup ->

next()

it 'should not allow a user with wrong password to login', (test, next) ->
it 'should not allow a user with wrong password to login and should respond after 500 msec', (test, next) ->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I combined the two tests into one primarily because the failed response now takes at least 0.5 seconds. If I test the delay separately, we will add another second, which wasn't really necessary...

Copy link
Owner

Choose a reason for hiding this comment

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

Sounds like solid reasoning. I would just move the comment below right above this and change it to:

# This test should take 500 msec or more. To speed up testing, these two tests have been combined.

Don't use "I" in any comments. It doesn't help anyone reading it, since they have no idea who "I" is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Updated.

@kahmali
Copy link
Owner

kahmali commented Jun 16, 2015

I think we should add this quick-fix in for now, and convert it to middleware after the v0.8.0 release. We can include this in the 0.7.0 release. The 0.7.0 release will be a mini auth update. Do you have any other quick auth updates you'd like to include before I publish it? It's best if we leave as much until after the 0.8.0 release as possible, since the middleware makes for a much cleaner, reusable pattern. I'll review this now.

@jazeee
Copy link
Contributor Author

jazeee commented Jun 16, 2015

I do not have any other updates.
Thanks much.
On Jun 16, 2015 11:57 AM, "Kahmali Rose" notifications@github.com wrote:

I think we should add this quick-fix in for now, and convert it to
middleware after the v0.8.0 release. We can include this in the 0.7.0
release. The 0.7.0 release will be a mini auth update. Do you have any
other quick auth updates you'd like to include before I publish it? It's
best if we leave as much until after the 0.8.0 release as possible, since
the middleware makes for a much cleaner, reusable pattern. I'll review this
now.


Reply to this email directly or view it on GitHub
#83 (comment)
.

# This is a simple, but not really adequate way to slow down unauthorized scans of the server.
# It is not sufficient because hackers can DDOS across multiple threads and systems.
timeoutInMilliseconds = 500
timeoutInMilliseconds *= (1 + Math.random())
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should change this to

randomMultiplierUpTo2X = 1 + Math.random()
delayInMilliseconds = 500 * randomMultiplierUpTo2X

I'm not in love with my variable name, but it gets rid of the magic number, and makes life a little easier for the math-challenged devs :) Also, I prefer "delay" over "timeout" for the other variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about randomMultiplierBetweenOneAndTwo.
Agreed with delay vs timeout.

@kahmali
Copy link
Owner

kahmali commented Jun 16, 2015

While reviewing this I realized that the 403 errors we returned in the last update are inaccurate. We should be returning a 401 whenever authentication fails. 403s should be reserved for permission errors. We should fix those (in a separate PR maybe).

@kahmali
Copy link
Owner

kahmali commented Jun 16, 2015

I left a few comments, but I've run out of time for now and will need to finish the last of the review tonight.

@jazeee
Copy link
Contributor Author

jazeee commented Jun 16, 2015

I tend to agree, 403 is for permission errors. In either case, 401 or 403, we should delay, so I suspect my original code is still ok.

@jazeee jazeee force-pushed the fix-issue-81-2 branch 2 times, most recently from 289265a to bc0db9f Compare June 16, 2015 19:53
# caused by bad user id vs bad password.
# In doing so, they can first scan for valid user ids regardless of valid passwords.
# Delay by a random amount to reduce the ability for a hacker to determine the response time.
# See https://en.wikipedia.org/wiki/Timing_attack
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated variable names. Added more comments to help understand why we do this.
Also added some links.

Copy link
Owner

Choose a reason for hiding this comment

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

I'm thinking we should only use the second comment. I'm open to debate here, but the first comment seems like it would be better suited if we added in a section to the docs about the current state of security in Restivus, and that could be included in the concerns that haven't been addressed. It doesn't really help to clarify the code any more than the second comment already does. It should also be moved to line 211 where the first comment already is (above this chunk of code).

@kahmali
Copy link
Owner

kahmali commented Jun 17, 2015

Your commit message must be wrapped at 72 chars. Also, I would remove the last bullet point (it kind of contradicts the first), and move the first bullet point to the bottom (to get to the good stuff first :D).

@kahmali
Copy link
Owner

kahmali commented Jun 17, 2015

I left some minor comments, but other than those, LGTM.

@jazeee
Copy link
Contributor Author

jazeee commented Jun 17, 2015

I will update the commit message to 72 chars.
I would prefer that the length to be longer, but its ok... (72 chars harkens back to the DOS days, and we now have wide screen monitors, etc...)

 - When logging in or accessing a restricted ReST endpoint with invalid
   credentials, the system shall delay before responding.
 - Note that this is not a great fix, since hackers could distribute
   their requests across CPUs.
 - This is an initial temporary fix for kahmali#81
# caused by bad user id vs bad password.
# In doing so, they can first scan for valid user ids regardless of valid passwords.
# Delay by a random amount to reduce the ability for a hacker to determine the response time.
# See https://www.owasp.org/index.php/Blocking_Brute_Force_Attacks#Finding_Other_Countermeasures
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kept both links since they are relevant.

@kahmali
Copy link
Owner

kahmali commented Jun 17, 2015

I use a 100 char line limit in all my other files (and will update the markdown convention to use no line limit at all), so I tend to agree, but 72 chars is a widely adopted standard for git messages that I've come to accept. I suppose in future projects I may be convinced to extend the line limit, but for now it's just a convention to allow consistency when reading through the commit history.

I've reviewed everything here and it looks great to me. I'll go ahead and pull this in. I just need to update the README with a warning about the token invalidation, and then I'll bump the version and publish. I'll keep you posted on that.

Thanks for another solid contribution!

kahmali added a commit that referenced this pull request Jun 17, 2015
Add delay when accessing unauthorized ReST endpoints
@kahmali kahmali merged commit a94aa48 into kahmali:devel Jun 17, 2015
@kahmali kahmali deleted the fix-issue-81-2 branch July 7, 2015 18:02
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.

When I login with bad credentials, I should get a randomly delayed response
2 participants