Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
770381c0
Unverified
Commit
770381c0
authored
4 years ago
by
Joas Schilling
Browse files
Options
Downloads
Patches
Plain Diff
Correctly return ms delay when at max
Signed-off-by:
Joas Schilling
<
coding@schilljs.com
>
parent
931aca2f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/private/Security/Bruteforce/Throttler.php
+4
-3
4 additions, 3 deletions
lib/private/Security/Bruteforce/Throttler.php
with
4 additions
and
3 deletions
lib/private/Security/Bruteforce/Throttler.php
+
4
−
3
View file @
770381c0
...
@@ -53,6 +53,7 @@ use OCP\Security\Bruteforce\MaxDelayReached;
...
@@ -53,6 +53,7 @@ use OCP\Security\Bruteforce\MaxDelayReached;
class
Throttler
{
class
Throttler
{
public
const
LOGIN_ACTION
=
'login'
;
public
const
LOGIN_ACTION
=
'login'
;
public
const
MAX_DELAY
=
25
;
public
const
MAX_DELAY
=
25
;
public
const
MAX_DELAY_MS
=
25000
;
// in milliseconds
public
const
MAX_ATTEMPTS
=
10
;
public
const
MAX_ATTEMPTS
=
10
;
/** @var IDBConnection */
/** @var IDBConnection */
...
@@ -263,12 +264,12 @@ class Throttler {
...
@@ -263,12 +264,12 @@ class Throttler {
$firstDelay
=
0.1
;
$firstDelay
=
0.1
;
if
(
$attempts
>
self
::
MAX_ATTEMPTS
)
{
if
(
$attempts
>
self
::
MAX_ATTEMPTS
)
{
// Don't ever overflow. Just assume the maxDelay time:s
// Don't ever overflow. Just assume the maxDelay time:s
return
self
::
MAX_DELAY
;
return
self
::
MAX_DELAY
_MS
;
}
}
$delay
=
$firstDelay
*
2
**
$attempts
;
$delay
=
$firstDelay
*
2
**
$attempts
;
if
(
$delay
>
self
::
MAX_DELAY
)
{
if
(
$delay
>
self
::
MAX_DELAY
)
{
return
self
::
MAX_DELAY
;
return
self
::
MAX_DELAY
_MS
;
}
}
return
(
int
)
\ceil
(
$delay
*
1000
);
return
(
int
)
\ceil
(
$delay
*
1000
);
}
}
...
@@ -338,7 +339,7 @@ class Throttler {
...
@@ -338,7 +339,7 @@ class Throttler {
*/
*/
public
function
sleepDelayOrThrowOnMax
(
string
$ip
,
string
$action
=
''
):
int
{
public
function
sleepDelayOrThrowOnMax
(
string
$ip
,
string
$action
=
''
):
int
{
$delay
=
$this
->
getDelay
(
$ip
,
$action
);
$delay
=
$this
->
getDelay
(
$ip
,
$action
);
if
((
$delay
===
self
::
MAX_DELAY
*
1000
)
&&
$this
->
getAttempts
(
$ip
,
$action
,
0.5
)
>
self
::
MAX_ATTEMPTS
)
{
if
((
$delay
===
self
::
MAX_DELAY
_MS
)
&&
$this
->
getAttempts
(
$ip
,
$action
,
0.5
)
>
self
::
MAX_ATTEMPTS
)
{
// If the ip made too many attempts within the last 30 mins we don't execute anymore
// If the ip made too many attempts within the last 30 mins we don't execute anymore
throw
new
MaxDelayReached
(
'Reached maximum delay'
);
throw
new
MaxDelayReached
(
'Reached maximum delay'
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment