Symptoms
- Websites or applications, such as Node.js apps, that are reverse proxied through a
RewriteRulewith the[P]flag in an.htaccessfile return403 Forbiddenafter theea-apache24package is updated to version 2.4.71-2. - Applications created with the deprecated Ruby on Rails interface in cPanel return
403 Forbidden. -
The
.htaccessfile contains a proxy rule similar to the following:CONFIG_TEXT: RewriteRule ^(.*)$ http://127.0.0.1:3005/$1 [P,L]
-
The Apache error log
/etc/apache2/logs/error_logshows the following entry:CONFIG_TEXT: [rewrite:notice] [pid 12345:tid 12345] [client 203.0.113.2:0] [EA4-418] mod_rewrite: proxy [P] flag is not permitted in per-directory context (.htaccess/<Directory>); set 'RewriteOptions AllowPerDirProxy' in server/vhost config to allow it. Returning 403 for 'http://127.0.0.1:3005/'
Internal: Ticket tracking
Tag tickets for this issue with CPANEL-59078.
Cause
EasyApache 4 v25.101 (ea-apache24 2.4.71-2) includes a security hardening change that blocks the mod_rewrite proxy [P] flag in per-directory context (.htaccess, <Directory>, <Location> and <Files>), so that an account's .htaccess file cannot be used to proxy requests to services on the server that the account does not own. Proxy rules in server and virtual host configuration are not affected.
Resolution
Note: If the application was created with the deprecated Ruby on Rails interface, recreate it in Application Manager instead. See Can I use the Ruby on Rails or RubyGems interfaces in cPanel to create Ruby applications?
Replace the .htaccess proxy rule with a reverse proxy in the domain's virtual host configuration.
- Configure the reverse proxy for the domain with
ProxyPassas described in How do you create an Apache Reverse Proxy with mod_proxy?, using the address and port from the existingRewriteRule. -
Create a backup copy of the domain's
.htaccessfile:# cp -a /home/cpuser/public_html/.htaccess /home/cpuser/public_html/.htaccess.bak
- Remove the
RewriteRuleline with the[P]flag from/home/cpuser/public_html/.htaccess.
Move the proxy rule from .htaccess to the domain's virtual host configuration.
- Log into the server via SSH as the root user.
-
Create the include directories for the domain:
# mkdir -p /etc/apache2/conf.d/userdata/std/2_4/cpuser/example.com /etc/apache2/conf.d/userdata/ssl/2_4/cpuser/example.com
-
Create the file
/etc/apache2/conf.d/userdata/std/2_4/cpuser/example.com/proxy.confand the file/etc/apache2/conf.d/userdata/ssl/2_4/cpuser/example.com/proxy.confwith the following content:Note: Replace 3005 with the port your application listens on. In virtual host context the matched path starts with a slash, so the pattern is
^/(.*)$instead of^(.*)$.CONFIG_TEXT: RewriteEngine On
RewriteRule ^/(.*)$ http://127.0.0.1:3005/$1 [P,L] -
Create a backup copy of the domain's
.htaccessfile:# cp -a /home/cpuser/public_html/.htaccess /home/cpuser/public_html/.htaccess.bak
- Remove the
RewriteRuleline with the[P]flag from/home/cpuser/public_html/.htaccess. -
Rebuild the Apache configuration and restart Apache:
# /scripts/rebuildhttpdconf && /scripts/restartsrv_httpd
- To revert, delete both
proxy.conffiles, restore/home/cpuser/public_html/.htaccess.bakto/home/cpuser/public_html/.htaccess, and run the command from step 6 again.
Allow per-directory proxy rules for a single domain.
Warning: This restores the previous behavior for every .htaccess file under the domain and removes the protection added by the security update for that domain. Use it only for domains whose files you fully trust. Place the file only in the domain's own directory as shown below. A file placed directly in /etc/apache2/conf.d/userdata/std/2_4/ or /etc/apache2/conf.d/userdata/ssl/2_4/ applies to every domain on the server.
- Log into the server via SSH as the root user.
-
Create the include directories for the domain:
# mkdir -p /etc/apache2/conf.d/userdata/std/2_4/cpuser/example.com /etc/apache2/conf.d/userdata/ssl/2_4/cpuser/example.com
-
Create the file
/etc/apache2/conf.d/userdata/std/2_4/cpuser/example.com/allow_perdir_proxy.confand the file/etc/apache2/conf.d/userdata/ssl/2_4/cpuser/example.com/allow_perdir_proxy.confwith the following content:Note: This directive only works in server or virtual host configuration. Adding it to an
.htaccessfile has no effect.CONFIG_TEXT: RewriteOptions AllowPerDirProxy
-
Rebuild the Apache configuration and restart Apache:
# /scripts/rebuildhttpdconf && /scripts/restartsrv_httpd
- To revert, delete both
allow_perdir_proxy.conffiles and run the command from step 4 again.
Comments
0 comments
Please sign in to leave a comment.