Skip to content

Commit 4c948dc

Browse files
authored
Merge pull request #163 from Extendy/mohd
bug: fix Clickjacking bug #160
2 parents d398402 + 000c6ce commit 4c948dc

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

app/Config/Filters.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Filters extends BaseConfig
2828
'afterlangchange' => \App\Filters\LangFilter::class, // it is just a test just to show how filter works , mshannaq not real filter
2929
'webratelimit' => \App\Filters\Webratelimit::class,
3030
'smartyglobal' => \App\Filters\SmartyglobalFilter::class,
31+
'clickjacking' => \App\Filters\ClickjackingFilter::class,
3132

3233
// if you want to define alias for multiple filter see https://forum.codeigniter.com/thread-76946.html
3334

@@ -66,11 +67,13 @@ class Filters extends BaseConfig
6667
// 'session' => ['except' => ['/', 'go/*', 'tests*', 'lang*', 'account/login*', 'account/register', 'account/auth/a/*']],
6768
// 'invalidchars',
6869
'smartyglobal', // global filter for SmartyUrl
70+
6971
],
7072
'after' => [
7173
'toolbar',
7274
// 'honeypot',
7375
// 'secureheaders',
76+
'clickjacking', // check security headers to mitigate clickjacking
7477
],
7578
];
7679

app/Filters/ClickjackingFilter.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Filters;
4+
5+
use CodeIgniter\HTTP\RequestInterface;
6+
use CodeIgniter\HTTP\ResponseInterface;
7+
use CodeIgniter\Filters\FilterInterface;
8+
9+
class ClickjackingFilter implements FilterInterface
10+
{
11+
public function before(RequestInterface $request, $arguments = null)
12+
{
13+
// Nothing to do before controller runs
14+
}
15+
16+
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
17+
{
18+
// Add security headers to mitigate clickjacking
19+
// Block all framing from anywhere
20+
$response->setHeader('X-Frame-Options', 'DENY');
21+
$response->setHeader('Content-Security-Policy', "frame-ancestors 'none';");
22+
return $response;
23+
}
24+
}

0 commit comments

Comments
 (0)