Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
crowdsec
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
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
project
crowdsec
Commits
0d43d024
Commit
0d43d024
authored
2 weeks ago
by
Jürgen Haas
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3524329
by jurgenhaas: Signal context
parent
81c0950a
No related branches found
No related tags found
No related merge requests found
Pipeline
#497072
passed
2 weeks ago
Stage: build
Stage: validate
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
crowdsec.services.yml
+1
-0
1 addition, 0 deletions
crowdsec.services.yml
src/Buffer.php
+14
-4
14 additions, 4 deletions
src/Buffer.php
src/EventSubscriber/CrowdSec.php
+2
-1
2 additions, 1 deletion
src/EventSubscriber/CrowdSec.php
with
17 additions
and
5 deletions
crowdsec.services.yml
+
1
−
0
View file @
0d43d024
...
...
@@ -56,6 +56,7 @@ services:
-
'
@ban.ip_manager'
-
'
@queue'
-
'
@event_dispatcher'
-
'
@request_stack'
crowdsec.cti
:
class
:
Drupal\crowdsec\Cti
...
...
This diff is collapsed.
Click to expand it.
src/Buffer.php
+
14
−
4
View file @
0d43d024
...
...
@@ -24,6 +24,8 @@ use Drupal\crowdsec\Event\CrowdSecEvents;
use
Drupal\crowdsec\Event\IpBanned
;
use
Drupal\crowdsec\Event\IpSignalled
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\RequestStack
;
/**
* Implements the CrowdSec buffer service.
...
...
@@ -63,6 +65,13 @@ class Buffer {
*/
protected
QueueInterface
$queue
;
/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected
Request
$request
;
/**
* Constructs the storage implementation.
*/
...
...
@@ -78,11 +87,13 @@ class Buffer {
protected
BanIpManagerInterface
$banIpManager
,
protected
QueueFactory
$queueFactory
,
protected
EventDispatcherInterface
$eventDispatcher
,
protected
RequestStack
$requestStack
,
)
{
$this
->
keyValue
=
$keyValueFactory
->
get
(
'crowdsec'
);
$this
->
expirableKeyValue
=
$keyValueExpirableFactory
->
get
(
'crowdsec'
);
$this
->
config
=
$configFactory
->
get
(
'crowdsec.settings'
);
$this
->
queue
=
$queueFactory
->
get
(
'crowdsec'
,
TRUE
);
$this
->
request
=
$this
->
requestStack
->
getCurrentRequest
();
}
/**
...
...
@@ -114,11 +125,10 @@ class Buffer {
* The target user in case of a brute force attack.
*/
public
function
addCurrentContext
(
array
&
$context
,
int
$status
,
?string
$targetUser
=
NULL
):
void
{
$request
=
\Drupal
::
request
();
$currentContext
=
[
'target_uri'
=>
$request
->
getRequestUri
(),
'user_agent'
=>
$request
->
headers
->
get
(
'User-Agent'
),
'method'
=>
$request
->
getMethod
(),
'target_uri'
=>
$
this
->
request
->
getRequestUri
(),
'user_agent'
=>
$
this
->
request
->
headers
->
get
(
'User-Agent'
),
'method'
=>
$
this
->
request
->
getMethod
(),
'status'
=>
$status
,
];
if
(
$targetUser
!==
NULL
)
{
...
...
This diff is collapsed.
Click to expand it.
src/EventSubscriber/CrowdSec.php
+
2
−
1
View file @
0d43d024
...
...
@@ -61,6 +61,7 @@ class CrowdSec extends HttpExceptionSubscriberBase {
if
(
empty
(
$ip
))
{
return
;
}
/** @var \Symfony\Component\HttpKernel\Exception\HttpExceptionInterface $exception */
$exception
=
$event
->
getThrowable
();
$this
->
buffer
->
addWhisperSignal
(
$ip
,
$exception
->
getStatusCode
());
}
...
...
@@ -74,7 +75,7 @@ class CrowdSec extends HttpExceptionSubscriberBase {
public
function
onBlockIp
(
UserFloodEvent
$event
):
void
{
$context
=
[];
if
(
$event
->
getName
()
===
UserEvents
::
FLOOD_BLOCKED_USER
)
{
$this
->
buffer
->
addCurrentContext
(
$context
,
403
,
$event
->
getUid
());
$this
->
buffer
->
addCurrentContext
(
$context
,
403
,
(
string
)
$event
->
getUid
());
}
else
{
$this
->
buffer
->
addCurrentContext
(
$context
,
403
);
...
...
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