fix(security): Add security hardening and CSRF protection.
Added .htaccess rules to deny access to hidden files. Escaped JSON output in views to prevent XSS attacks. Converted delete links and forms to use POST with CSRF tokens. Enforced POST method on sensitive routes. Added tests to verify these security controls.
This commit is contained in:
@@ -17,6 +17,10 @@ if(isset($_GET['id']))
|
||||
$form = $formsRepository->findWithId($_GET['id']);
|
||||
|
||||
$isEditing = isset($form['id']) && $form['id'] > 0;
|
||||
$fieldsJson = json_encode(json_decode($form['fields']) ?? [], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
|
||||
$finishersJson = json_encode(json_decode($form['finishers']) ?? [], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);
|
||||
$fieldsJson = $fieldsJson === false ? '[]' : $fieldsJson;
|
||||
$finishersJson = $finishersJson === false ? '[]' : $finishersJson;
|
||||
?>
|
||||
|
||||
<header class="mb-6 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
@@ -34,8 +38,8 @@ $isEditing = isset($form['id']) && $form['id'] > 0;
|
||||
</header>
|
||||
|
||||
<script>
|
||||
const fields = <?= $form["fields"] ?>;
|
||||
const finishers = <?= $form["finishers"] ?>;
|
||||
const fields = <?= $fieldsJson ?>;
|
||||
const finishers = <?= $finishersJson ?>;
|
||||
const finisherDefinitions = <?= json_encode($finisherDefinitions, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT) ?>;
|
||||
</script>
|
||||
|
||||
@@ -102,6 +106,7 @@ $isEditing = isset($form['id']) && $form['id'] > 0;
|
||||
this.fields.splice(toIndex, 0, field);
|
||||
}
|
||||
}">
|
||||
<?php phpb_csrf_field(); ?>
|
||||
<?php
|
||||
if(isset($form['id'])) echo '<input type="hidden" name="id" value="'.$form['id'].'">';
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user