Skip to content

Commit

Permalink
fix: only allow 5 mails per user, don't allow the user to change the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jan 12, 2024
1 parent 1348dce commit a34d94a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
22 changes: 19 additions & 3 deletions phpmyfaq/api.service.php
Original file line number Diff line number Diff line change
Expand Up @@ -771,14 +771,30 @@

$author = trim((string) Filter::filterVar($postData['name'], FILTER_SANITIZE_SPECIAL_CHARS));
$email = Filter::filterVar($postData['email'], FILTER_VALIDATE_EMAIL);
$link = trim((string) Filter::filterVar($postData['link'], FILTER_VALIDATE_URL));
$attached = trim((string) Filter::filterVar($postData['message'], FILTER_SANITIZE_SPECIAL_CHARS));
$mailto = Filter::filterArray($postData['mailto[]']);

$faqLanguage = trim((string) Filter::filterVar($postData['lang'], FILTER_SANITIZE_SPECIAL_CHARS));
$faqId = trim((string) Filter::filterVar($postData['faqId'], FILTER_VALIDATE_INT));
$categoryId = trim((string) Filter::filterVar($postData['categoryId'], FILTER_VALIDATE_INT));

if (is_array($mailto) && count($mailto) > 5) {
$response->setStatusCode(Response::HTTP_BAD_REQUEST);
$response->setData(['error' => Translation::get('err_sendMail')]);
break;
}

if (
!is_null($author) && !is_null($email) && is_array($mailto) &&
$stopWords->checkBannedWord(Strings::htmlspecialchars($attached))
) {
$send2friendLink = sprintf(
'%sindex.php?action=faq&cat=%d&id=%d&artlang=%s',
$faqConfig->getDefaultUrl(),
$categoryId,
$faqId,
urlencode($faqLanguage)
);

foreach ($mailto as $recipient) {
$recipient = trim(strip_tags((string) $recipient));
Expand All @@ -796,8 +812,8 @@
"%s\r\n\r\n%s\r\n%s\r\n\r\n%s",
$faqConfig->get('main.send2friendText'),
Translation::get('msgS2FText2'),
$link,
$attached
$send2friendLink,
strip_tags($attached)
);

// Send the email
Expand Down
6 changes: 4 additions & 2 deletions phpmyfaq/assets/themes/default/templates/send2friend.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
</div>

<form id="formValues" action="#" method="post" accept-charset="utf-8" class="needs-validation" novalidate>
<input type="hidden" name="{{ msgS2FReferrer }}" value="{{ send2friendLink }}" />
<input type="hidden" name="lang" id="lang" value="{{ lang }}" />
<input type="hidden" name="{{ msgS2FReferrer }}" value="{{ send2friendLink }}">
<input type="hidden" name="lang" id="lang" value="{{ lang }}">
<input type="hidden" name="faqId" id="faqId" value="{{ faqId }}">
<input type="hidden" name="categoryId" id="categoryId" value="{{ categoryId }}">

<div class="row mb-2">
<label class="col-sm-3 form-control-label" for="name">{{ msgS2FName }}</label>
Expand Down
2 changes: 2 additions & 0 deletions phpmyfaq/send2friend.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
'mainPageContent',
[
'lang' => Strings::htmlentities($faqLanguage),
'faqId' => $faqId,
'categoryId' => $faqCategory,
'msgSend2Friend' => Translation::get('msgSend2Friend'),
'msgS2FReferrer' => 'link',
'msgS2FName' => Translation::get('msgS2FName'),
Expand Down

0 comments on commit a34d94a

Please sign in to comment.