Skip to content

Commit 2cd74e9

Browse files
Sanitize clarification bodies.
1 parent 305a88b commit 2cd74e9

File tree

6 files changed

+254
-6
lines changed

6 files changed

+254
-6
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"symfony/flex": "^2",
8585
"symfony/form": "6.3.*",
8686
"symfony/framework-bundle": "6.3.*",
87+
"symfony/html-sanitizer": "6.3.*",
8788
"symfony/http-client": "6.3.*",
8889
"symfony/intl": "6.3.*",
8990
"symfony/mime": "6.3.*",

composer.lock

Lines changed: 244 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp/src/Controller/Jury/ClarificationController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use App\Utils\Utils;
1515
use Doctrine\ORM\EntityManagerInterface;
1616
use Doctrine\ORM\Query\Expr\Join;
17+
use Symfony\Component\HtmlSanitizer\HtmlSanitizerInterface;
1718
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
1819
use Symfony\Component\Security\Http\Attribute\IsGranted;
1920
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -384,7 +385,7 @@ public function changeQueueAction(Request $request, int $clarId): Response
384385
}
385386

386387
#[Route(path: '/send', methods: ['POST'], name: 'jury_clarification_send')]
387-
public function sendAction(Request $request): Response
388+
public function sendAction(Request $request, HtmlSanitizerInterface $htmlSanitizer): Response
388389
{
389390
$clarification = new Clarification();
390391

@@ -436,7 +437,7 @@ public function sendAction(Request $request): Response
436437

437438
$clarification->setJuryMember($this->getUser()->getUserIdentifier());
438439
$clarification->setAnswered(true);
439-
$clarification->setBody($request->request->get('bodytext'));
440+
$clarification->setBody($htmlSanitizer->sanitize($request->request->get('bodytext')));
440441
$clarification->setSubmittime(Utils::now());
441442

442443
$this->em->persist($clarification);

webapp/src/Controller/RootController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Service\DOMJudgeService;
66
use Symfony\Component\DependencyInjection\Attribute\Autowire;
7+
use Symfony\Component\HtmlSanitizer\HtmlSanitizerInterface;
78
use Symfony\Component\HttpFoundation\JsonResponse;
89
use Symfony\Component\HttpFoundation\RedirectResponse;
910
use Symfony\Component\HttpFoundation\Request;
@@ -43,12 +44,13 @@ public function redirectAction(AuthorizationCheckerInterface $authorizationCheck
4344
public function markdownPreview(
4445
Request $request,
4546
#[Autowire(service: 'twig.runtime.markdown')]
46-
MarkdownRuntime $markdownRuntime
47+
MarkdownRuntime $markdownRuntime,
48+
HtmlSanitizerInterface $htmlSanitizer
4749
): JsonResponse {
4850
$message = $request->request->get('message');
4951
if ($message === null) {
5052
throw new BadRequestHttpException('A message is required');
5153
}
52-
return new JsonResponse(['html' => $markdownRuntime->convert($message)]);
54+
return new JsonResponse(['html' => $markdownRuntime->convert($htmlSanitizer->sanitize($message))]);
5355
}
5456
}

webapp/src/Entity/Clarification.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,6 @@ public function getSummary(): string
356356
$newBody .= $line . ' ';
357357
}
358358
}
359-
return Utils::cutString((empty($newBody) ? $this->getBody() : $newBody), 80);
359+
return Utils::cutString(html_entity_decode((empty($newBody) ? $this->getBody() : $newBody)), 80);
360360
}
361361
}

webapp/src/Form/Type/TeamClarificationType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
5050
]);
5151
$builder->add('message', TextareaType::class, [
5252
'label' => false,
53+
'sanitize_html' => true,
5354
'attr' => [
5455
'rows' => 5,
5556
'cols' => 85,

0 commit comments

Comments
 (0)