Skip to content

Commit 7cbe1f6

Browse files
committed
Reports/Fixup
* also include source url when checking target context * cleanup source url to be usable as key
1 parent 3a25c23 commit 7cbe1f6

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

includes/components/report.class.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ public function __construct(private int $mode, private int $reason, private ?int
144144
$this->subject ??= 0; // 0 for utility, tools and misc pages?
145145
}
146146

147-
private function checkTargetContext() : int
147+
private function checkTargetContext(?string $url) : int
148148
{
149149
// check already reported
150150
$field = User::isLoggedIn() ? 'userId' : 'ip';
151-
if (DB::Aowow()->selectCell('SELECT 1 FROM ?_reports WHERE `mode` = ?d AND `reason`= ?d AND `subject` = ?d AND ?# = ?', $this->mode, $this->reason, $this->subject, $field, User::$id ?: User::$ip))
151+
if (DB::Aowow()->selectCell('SELECT 1 FROM ?_reports WHERE `mode` = ?d AND `reason`= ?d AND `subject` = ?d{ AND `url` = ?} AND ?# = ?', $this->mode, $this->reason, $this->subject, $url ?: DBSIMPLE_SKIP, $field, User::$id ?: User::$ip))
152152
return self::ERR_ALREADY_REPORTED;
153153

154154
// check targeted post/postOwner staff status
@@ -190,7 +190,28 @@ public function create(string $desc, ?string $userAgent = null, ?string $appName
190190
return false;
191191
}
192192

193-
if($err = $this->checkTargetContext())
193+
// clean up src url: dont use anchors, clean up query
194+
if ($pageUrl)
195+
{
196+
$urlParts = parse_url($pageUrl);
197+
if (!empty($urlParts['query']))
198+
{
199+
parse_str($urlParts['query'], $query); // kills redundant param declarations
200+
unset($query['locale']); // locale param shouldn't be needed. more..?
201+
$urlParts['query'] = http_build_query($query);
202+
}
203+
204+
$pageUrl = '';
205+
if (isset($urlParts['scheme']))
206+
$pageUrl .= $urlParts['scheme'].':';
207+
208+
$pageUrl .= '//'.($urlParts['host'] ?? '').($urlParts['path'] ?? '');
209+
210+
if (isset($urlParts['query']))
211+
$pageUrl .= '?'.$urlParts['query'];
212+
}
213+
214+
if ($err = $this->checkTargetContext($pageUrl))
194215
{
195216
$this->errorCode = $err;
196217
return false;

0 commit comments

Comments
 (0)