TL;DR
An attacker is using an iFrame to launch a brute force attack against your website. This guide shows you how to identify and block this type of attack, focusing on server-side configuration and Content Security Policy (CSP).
Understanding the Attack
Attackers embed malicious code within an iFrame hosted on their own server. Your users visit a page containing this iFrame. The iFrame then attempts to guess usernames and passwords by repeatedly submitting login forms, often at high speed. This bypasses client-side security measures like CAPTCHAs.
Step 1: Identify the Attack in Logs
- Check your web server logs: Look for a large number of POST requests to your login endpoint originating from a single IP address or a small range of IPs.
- Examine request patterns: Brute force attacks often have predictable patterns – many failed login attempts in quick succession.
- Identify the referring domain: The logs should show that these requests are coming from an external domain hosting the malicious iFrame.
Example log entry (Apache):
192.168.1.10 - - [10/Oct/2023:14:55:32 +0000] "POST /login HTTP/1.1" 401 256 "http://attackerdomain.com/malicious_iframe.html" ...
Step 2: Block the Attacking IP Address(es)
- Firewall Rules: Add rules to your firewall (e.g., iptables, ufw, AWS Security Groups, Cloudflare Firewall) to block traffic from the attacker’s IP address(es).
- Web Server Configuration: Configure your web server (e.g., Apache .htaccess, Nginx config) to deny access based on IP address.
Example .htaccess rule:
<Limit POST /login>
Order Deny,Allow
Deny from 192.168.1.10
Allow from all
</Limit>
Step 3: Implement Content Security Policy (CSP)
CSP is the most effective long-term solution. It tells the browser which sources are allowed to load resources, preventing your page from loading content from untrusted domains.
- Define a strict CSP: Start with a restrictive policy and gradually allow trusted sources as needed.
- Block iFrame embedding: Specifically prevent your site from being embedded in an iFrame from unknown origins.
Example CSP header:
Content-Security-Policy: default-src 'self'; frame-ancestors 'none';
This policy allows resources only from your own domain and prevents any iFrame embedding.
Step 4: Rate Limiting
- Implement rate limiting on login endpoints: Limit the number of login attempts allowed per IP address within a specific timeframe.
- Use web server modules or third-party tools: Apache’s
mod_ratelimit, Nginx’slimit_req_zoneandlimit_conn_zoneare useful options.
Example Nginx rate limiting configuration:
http {
...
limit_req_zone $binary_remote_addr zone=mylimit:10m rate=5r/s;
server {
...
location /login {
limit_req zone=mylimit burst=10 nodelay;
...
}
}
}
This limits login attempts to 5 per second, with a burst allowance of 10.
Step 5: CAPTCHA (as an additional layer)
- Implement CAPTCHA on the login form: While not foolproof against sophisticated attacks, it adds another hurdle for automated bots.
- Use a reputable CAPTCHA provider: Google reCAPTCHA is a common choice.
Step 6: Monitor and Refine
Regularly review your logs, CSP reports, and firewall rules to identify new attack patterns and adjust your security measures accordingly. cyber security is an ongoing process.

