Harden the app: block project files, add rate limits and security headers

- Root .htaccess refuses everything outside public/, because local Apache
  serves the whole project folder (.env, logs with set-password links, .git).
- Login allows 20 failed attempts a minute per IP across accounts, besides
  5 per email and IP; the forgot-password page 5 requests a minute per IP.
- A global middleware sends X-Frame-Options, frame-ancestors, nosniff,
  Referrer-Policy, Permissions-Policy and HSTS over HTTPS, and drops
  X-Powered-By.
- The weekly time sheet locks the shown week and selected day, so the
  browser cannot set them.
- Users who may not see personal identity codes can save a new code at
  most 10 times an hour, so the duplicate check cannot be used to test codes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 06:25:26 +02:00
co-authored by Claude Opus 5.5
parent fcad0ea939
commit 1acdaa5b19
15 changed files with 229 additions and 8 deletions
@@ -144,3 +144,23 @@ it('drops the code when a consumer becomes a company', function () {
expect($customer->fresh()->personal_identity_code)->toBeNull();
});
it('limits how many codes an employee can try, but not management', function (string $role, bool $limited) {
$this->actingAs(User::factory()->create(['role' => $role]));
$form = Livewire::test('customers::form')
->set('form.name', 'Maija Meikäläinen')
->set('form.type', CustomerType::Consumer->value);
foreach (range(1, 10) as $attempt) {
$form->set('form.personal_identity_code', 'väärä')->call('save')->assertHasErrors(['form.personal_identity_code']);
}
$form->set('form.personal_identity_code', '131052-308T')->call('save');
$limited
? $form->assertSee('liian monta kertaa tunnin aikana')
: $form->assertHasNoErrors();
})->with([
'employee' => ['employee', true],
'management' => ['management', false],
]);