Blog | G5 Cyber Security

404 Page Clickjacking Risk

TL;DR

Yes, a 404 (or other error) page served without the X-Frame-Options header can be vulnerable to clickjacking. Attackers can trick users into clicking something different than they think by overlaying the error page in an iframe on their malicious site.

Understanding the Risk

Clickjacking exploits rely on deceiving a user into performing actions within a hidden frame. If your 404 page doesn’t prevent being loaded inside an iframe, it can be used for this purpose. Even though it’s just an error page, malicious actors could use it to:

How to Protect Your 404 Page

The primary defence against clickjacking is the X-Frame-Options HTTP response header. Here’s how to implement it:

1. Configure Your Web Server

You need to add the X-Frame-Options header to your web server’s configuration for your error pages (specifically, the 404 page). The exact method depends on your server.

Apache

Header always set X-Frame-Options "SAMEORIGIN"

Add this line to your .htaccess file or your virtual host configuration. SAMEORIGIN means the page can only be framed by pages on the same domain.

Nginx

add_header X-Frame-Options "SAMEORIGIN";

Add this line to your server block configuration file. Again, SAMEORIGIN is generally a good choice.

Microsoft IIS

Use the URL Rewrite module or configure custom headers in IIS Manager. Set the header name to X-Frame-Options and the value to SAMEORIGIN.

2. Content Security Policy (CSP)

While X-Frame-Options is simpler, CSP offers more control. You can use the frame-ancestors directive:

Content-Security-Policy: frame-ancestors 'self';

This achieves the same result as X-Frame-Options SAMEORIGIN.

3. Test Your Configuration

Verify that your header is being sent correctly:

4. Example Clickjacking Attempt (for demonstration)

An attacker might use code like this (simplified HTML):

<iframe src="https://yourdomain.com/404" style="border:none; width:100%; height:500px;"></iframe>

Without X-Frame-Options, this iframe will load your 404 page. The attacker can then overlay it with other elements to trick the user.

Important Considerations

Exit mobile version