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'].'">';
|
||||
?>
|
||||
|
||||
@@ -75,9 +75,14 @@ $entries = $entriesRepository->findWhere('formId', $id);
|
||||
<?php endforeach; ?>
|
||||
<td>
|
||||
<div class="flex justify-end">
|
||||
<a href="/ext--form/delete-entry?id=<?= $entry['id'] ?>&formId=<?= $id ?>" class="btn btn-ghost btn-square btn-sm text-error" title="<?= phpb_trans('website-manager.remove') ?>" aria-label="<?= phpb_trans('website-manager.remove') ?> submission <?= phpb_e($entry['id']) ?>">
|
||||
<i class="ph-duotone ph-trash text-lg" aria-hidden="true"></i>
|
||||
</a>
|
||||
<form action="/ext--form/delete-entry" method="post">
|
||||
<?php phpb_csrf_field(); ?>
|
||||
<input type="hidden" name="id" value="<?= phpb_e((string) $entry['id']) ?>">
|
||||
<input type="hidden" name="formId" value="<?= phpb_e((string) $id) ?>">
|
||||
<button type="submit" class="btn btn-ghost btn-square btn-sm text-error" title="<?= phpb_trans('website-manager.remove') ?>" aria-label="<?= phpb_trans('website-manager.remove') ?> submission <?= phpb_e($entry['id']) ?>">
|
||||
<i class="ph-duotone ph-trash text-lg" aria-hidden="true"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -58,9 +58,13 @@ $forms = $formsRepository->getAll();
|
||||
<a href="<?= phpb_url('website_manager', ['tab' => 'ext--form', 'action' => 'editForm', 'id' => $form['id']]) ?>" class="btn btn-ghost btn-square btn-sm" title="<?= phpb_trans('website-manager.edit') ?>" aria-label="<?= phpb_trans('website-manager.edit') ?> <?= phpb_e($form['name']) ?>">
|
||||
<i class="ph-duotone ph-pencil-line text-lg" aria-hidden="true"></i>
|
||||
</a>
|
||||
<a href="/ext--form/delete-form?id=<?= $form['id'] ?>" class="btn btn-ghost btn-square btn-sm text-error" title="<?= phpb_trans('website-manager.remove') ?>" aria-label="<?= phpb_trans('website-manager.remove') ?> <?= phpb_e($form['name']) ?>">
|
||||
<i class="ph-duotone ph-trash text-lg" aria-hidden="true"></i>
|
||||
</a>
|
||||
<form action="/ext--form/delete-form" method="post">
|
||||
<?php phpb_csrf_field(); ?>
|
||||
<input type="hidden" name="id" value="<?= phpb_e((string) $form['id']) ?>">
|
||||
<button type="submit" class="btn btn-ghost btn-square btn-sm text-error" title="<?= phpb_trans('website-manager.remove') ?>" aria-label="<?= phpb_trans('website-manager.remove') ?> <?= phpb_e($form['name']) ?>">
|
||||
<i class="ph-duotone ph-trash text-lg" aria-hidden="true"></i>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user