Skip to content
Projects
Groups
Snippets
Help
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project overview
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
301
Merge Requests
38
CI / CD
Security & Compliance
Packages
Wiki
Snippets
Members
Collapse sidebar
Close sidebar
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
e71d585d
Commit
e71d585d
authored
2 hours ago
by
Ben Hayward
Browse files
Options
Download
Spam detection
#1104
parent
c884098b
fix/spam-detection-return-1104
1 merge request
!391
[Sprint/RollingRabbit](fix): Updated returned exception of offending spam link. #1104
Pipeline
#97062069
passed with stages
in 7 minutes and 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
41 deletions
+10
-41
Core/Security/Events.php
View file @
e71d585d
...
...
@@ -7,23 +7,20 @@ use Minds\Core\Events\Dispatcher;
use
Minds\Core\Security\TwoFactor
;
use
Minds\Exceptions
;
use
Minds\Helpers\Text
;
use
Minds\Core\Security\
ProhibitedDomains
;
use
Minds\Core\Security\
Spam
;
class
Events
{
/** @var SMS $sms */
protected
$sms
;
/** @var
Config $config
*/
protected
$
config
;
/** @var
Spam
*/
protected
$
spam
;
/** @var ProhibitedDomains */
protected
$prohibitedDomains
;
public
function
__construct
(
$prohibitedDomains
=
null
)
public
function
__construct
(
$spam
=
null
)
{
$this
->
sms
=
Di
::
_
()
->
get
(
'SMS'
);
$this
->
prohibitedDomains
=
$prohibitedDomains
??
new
ProhibitedDomains
();
$this
->
spam
=
$spam
??
new
Spam
();
}
public
function
register
()
...
...
@@ -36,47 +33,17 @@ class Events
public
function
onCreateHook
(
$hook
,
$type
,
$params
,
$return
=
null
)
{
$object
=
$params
;
$foundSpam
=
$this
->
containsProhibitedDomain
(
$object
);
if
(
$foundSpam
)
{
throw
new
\Exception
(
"Sorry, you included a reference to a domain name linked to spam (${foundSpam})"
);
if
(
$this
->
spam
->
check
(
$object
))
{
if
(
PHP_SAPI
!=
'cli'
)
{
forward
(
REFERRER
);
}
return
false
;
}
if
(
$type
==
'group'
&&
$this
->
strposa
(
$object
->
getBriefDescription
(),
$this
->
prohibitedDomains
()))
{
return
false
;
}
return
true
;
}
/**
* Returns true if the object bodies contain a prohibited domain.
*
* @param $object - excepts fields description, briefdescription, message and title.
* @return boolean - true if prohibited domain found.
*/
public
function
containsProhibitedDomain
(
$object
)
:
string
{
$prohibitedDomains
=
$this
->
prohibitedDomains
->
get
();
$bodies
=
[
$object
->
description
,
$object
->
briefdescription
,
$object
->
message
,
$object
->
title
];
foreach
(
$bodies
as
$text
)
{
$found
=
Text
::
strposa
(
$text
,
$prohibitedDomains
);
if
(
$found
)
{
return
$found
;
}
}
return
""
;
}
/**
* Twofactor authentication login hook
*/
...
...
This diff is collapsed.
Core/Security/Spam.php
View file @
e71d585d
...
...
@@ -8,8 +8,8 @@ use Minds\Core\Security\ProhibitedDomains;
class
Spam
{
/** @var
Config $config
*/
protected
$
config
;
/** @var
ProhibitedDomains $prohibitedDomains
*/
protected
$
prohibitedDomains
;
public
function
__construct
(
$prohibitedDomains
=
null
...
...
@@ -27,6 +27,8 @@ class Spam
$foundSpam
=
Text
::
strposa
(
$entity
->
getBody
(),
$prohibitedDomains
);
break
;
case
'activity'
:
$foundSpam
=
Text
::
strposa
(
$entity
->
getMessage
(),
$prohibitedDomains
);
break
;
case
'object'
:
if
(
$entity
->
getSubtype
()
===
'blog'
)
{
$foundSpam
=
Text
::
strposa
(
$entity
->
getBody
(),
$prohibitedDomains
);
...
...
This diff is collapsed.
Please
register
or
sign in
to comment