Skip to content

reCAPTCHA

As of LiteSpeed Web Server 5.4, reCAPTCHA is available as a method of defense against DDoS attack.

Tip

reCAPTCHA may also be used as a method of WordPress Brute Force Attack Protection. Please see the WP-Protect Guide for more information about that.

Note

reCAPTCHA activation is dependent on the URL being accessed. It does not activate for API urls. reCAPTCHA only activates for URLs accessed by real clients.

Enable Globally at the Server Level

Access the WebAdmin console via https://YOUR_SERVER_IP:7080

Navigate to Configuration > Server > Security > reCAPTCHA Protection

!reCAPTCHA protection

Set Enable reCAPTCHA to Yes. This is the master switch and it is required for both a control panel environment and an LSWS native environment. It will enable the reCAPTCHA feature for all control panel Apache virtual hosts as well as LSWS native virtual hosts globally. It may be overridden at the virtual host level.

For other options, hover over the ? symbol to view detailed information about that option.

For demonstration purposes, we will set Trigger Sensitivity to maximum (100), and reCAPTCHA Type to Checkbox. You may adjust these values according to your needs. Save and restart LSWS. This sensitivity setting will be inherited by all control panel Apache virtual hosts and LSWS native virtual hosts unless overridden at the virtual host level.

!reCAPTCHA configuration

After making the change described above, the appropriate directives will be added to the LiteSpeed configuration file /usr/local/lsws/conf/httpd_config.xml.

Alternatively, you can add them yourself. Edit the file via vi /usr/local/lsws/conf/httpd_config.xml, and place the following code after the <security>...</security> section: <lsrecaptcha> <enabled>1</enabled> <type>1</type> <sensitivity>100</sensitivity> </lsrecaptcha>

You can also enable reCAPTCHA on an individual virtual host that is under attack, while leaving other websites disabled.

Validation expiration time

When a visitor accesses the website, they will need to go though reCAPTCHA validation. This validation protects the server against HTTP Flood and other DDoS attacks.

After passing the reCAPTCHA validation, the visitor is temporarily whitelisted as long as they continue to browse the site. This makes for a better user experience. Once the visitor has been inactive for a specified time, reCAPTCHA is once again enabled for that visitor's next request.

Expiration defaults to one day, but is configurable to any number of seconds via the Verification Expires field.

!reCAPTCHA verification

Override/Disable at the Virtual Host Level

Assuming you have enabled reCAPTCHA at the server level globally, you can override the settings at a virtual host level, but how you do so depends on which environment you are using.

Override/Disable for Apache Virtual Hosts

As of LSWS v5.4RC4, you can configure vhost-level reCAPTCHA via the LsRecaptcha directive in the virtual host include configuration, like so:

<IfModule LiteSpeed>
   LsRecaptcha (0-100)
</IfModule>

The 0-100 value defines or overrides Trigger Sensitivity for the virtual host. When LsRecaptcha is set to 0, it means the reCAPTCHA feature has been disabled for that virtual host.

Note

The LsRecaptcha directive cannot be used in .htaccess files.

Set Max Conn to trigger reCAPTCHA

In an Apache configuration file, either at the server level, or at the virtual host level, you can add the LiteSpeed-specific configuration LsRecaptcha max_conn. The parameter value defines the maximum number of concurrent connections you can have before reCAPTCHA is automatically triggered.

Example

To set the maximum number of concurrent requests to 1000, use:

<IfModule LiteSpeed>
LsRecaptcha max_conn 1000
</IfModule>

Set the parameter value to 1 if you want to always have reCAPTCHA on. Set the value to 0 to disable reCAPTCHA.

LsRecaptcha max_conn used at the server level applies to all Apache virtual hosts, but the server-level setting may be overridden with a vhost-level configuration.

Override for LiteSpeed Native Virtual Hosts

Use the LSWS WebAdmin console to override reCAPTCHA in LSWS native mode.

Navigate to Configuration > Virtual Hosts > Security > reCAPTCHA Protection

!Override reCAPTCHA for virtual hosts

Set Trigger Sensitivity

Trigger Sensitivity refers to the automatic reCAPTCHA sensitivity. The higher the value, the more likely reCAPTCHA Protection will be used. A value of 0 is equivalent to “Off” while a value of 100 is equivalent to “Always On”.

Default Values

Server level: 0. Virtual Host level: inherits server-level setting. Syntax: Integer value between 0 and 100.

LiteSpeed calculates Trigger Sensitivity as the percentage of your server capacity used, based on the number of active connections. reCAPTCHA is activated when this formula is true:

Active connections * 100 / Max Connections > (100 - Trigger Sensitivity)

For example:

If Max Connections = 1000, Trigger Sensitivity = 20, and you currently have 900 connections, the formula would be evaluated like so:

900 * 100 / 1000 > 100 - 20

90 > 80

The result is true, so the incoming connection will be given a reCAPTCHA test.

Calculating backwards, you can see that when the number of connections drops to less than 800, reCAPTCHA will not be invoked.

Warning

We've discovered in real world usage that Trigger Sensitivity can be ineffective in some setups.

Here's why: Trigger Sensitivity is based on the number of active connections. But sometimes, sites have a large number of connections that are unrelated to the main page HTML. These extra connections don't result in anything that is visible to the user, but they require a high connection limit. The high connection limit negatively impacts the Trigger Sensitivity calculation, making most values under 100 behave effectively like 0.

In our experience, the headaches caused by trying to use Trigger Sensitivity under these conditions are not worth the benefits. If you have high connection limits set, we recommend two possible courses of action:

  • Go all or nothing: set the sensitivity to 100 (always on) or 0 (always off)
  • Use rewrite rules: Set sensitivity to 0 at the virtual host level, and then selectively enable reCAPTCHA for certain URLs via rewrite rules, like the following example, which applies to all URLs in the /admin/ directory.

This is how it would appear if added to the Apache virtual host configuration:

<IfModule LiteSpeed>
RewriteRule /admin/ - [E=verifycaptcha:deny]
</IfModule>

The same rule would need to look a bit different (no beginning / on admin/) if added to .htaccess, like this:

<IfModule LiteSpeed>
RewriteRule admin/ - [E=verifycaptcha:deny]
</IfModule>