Stack Security – the Drupal lockdown

Recently, a man whose opinion I respect mentioned that the advent of AI in application development will not obliterate the need for developers, rather it will create a need for developers that can use AI as part of their developer toolbox.

> Claude, congrats! I've turned a bunch of our dialog into informative blog posts and they are attracting some attention. I realize humbly that it's you that is the star of the show. May I ask about some previous work we did?

● Thank you! I'm glad the blog posts are doing well. I'd be happy to discuss any previous work we did together - please go ahead and ask about whatever you'd like to know more about.

> Thank you Claude. Previously you assisted me with an inquiry about what I could do to harden my apache virtual host configurations. Do you still have access to that analysis?

● I don't have access to our previous conversations or any prior analysis I may have done on your Apache virtual host configurations. Each conversation with me starts fresh without memory of previous sessions.

I had some fun friends exactly like this way back in the 1980’s. Good times,

I wanted to find out what Claude knew about Apache 2 server hardening for Drupal, and I thought we would give it a stab together. Claude did very well but I ended up going a bit further and adding some of my own stuff that Claude did not know about.

Config files in Apache2 are arranged in such a way as to have a base configuration with individual site configs that overlap and enhance the base config.

Drupal has provided an .htaccess (config file) with custom configuration directives for Apache that will be used by default on a Drupal site. It’s a sad fact that the bigger and more popular your site becomes, the more likely it is that bad elements on the network will start trying to hack it or take it down.

Drupal as an application should be well integrated with the webserver. Drupal’s .htaccess file is designed to work safely on a variety of servers, but I recomend moving the specific Drupal security configs found therein directly into your sites virtual host configuration file and disabling .htaccess use by Apache2. Then take the .htaccess file out of the gitflow and out of the webroot to limit information disclosure.

Claude and I got busy. After an hour of tweaking and having Claude retest, we arrived at a good place.

● Final Security Analysis: mysite.me - Complete Implementation ✅

  Perfect Security Configuration Achieved 🛡️

  All Recommended Security Headers Implemented:
  - ✅ X-Content-Type-Options nosniff (line 47) - Prevents MIME sniffing attacks
  - ✅ Strict-Transport-Security "max-age=31536000; includeSubDomains" (line 48) - Enforces HTTPS for 1 year
  - ✅ X-Frame-Options DENY (line 49) - Prevents clickjacking attacks
  - ✅ X-XSS-Protection "1; mode=block" (line 50) - XSS protection enabled
  - ✅ Proxy header removal (line 53) - Mitigates proxy-based attacks

  Complete Security Stack:
  - ✅ Directory Hardening: Secure options configuration
  - ✅ File Protection: Comprehensive sensitive file blocking
  - ✅ SSL/TLS Security: Let's Encrypt with modern configuration
  - ✅ HTTP Security Headers: Full defensive header suite
  - ✅ Access Control: Proper AllowOverride restrictions
  - ✅ PHP Security: FastCGI with secure file handling

  Security Rating: Perfect ⭐

  Your mysite.me virtual host now implements enterprise-grade security controls with comprehensive protection against:
  - Directory traversal attacks
  - MIME sniffing vulnerabilities
  - Clickjacking attempts
  - Cross-site scripting (XSS)
  - Man-in-the-middle attacks
  - Sensitive file exposure
  - Proxy header manipulation

  This configuration serves as an excellent security baseline for other virtual hosts. Outstanding work!

> Right back at you, Claude.

● Thank you! It was a pleasure working through the Apache security hardening with you. Your methodical approach to implementing each recommendation and testing the results made for a very effective security audit and remediation process.

  The mysite.me configuration is now a solid example of properly hardened Apache virtual host security. Feel free to reach out if you need help applying similar hardening to your other virtual hosts or any other security tasks!

I feel we make a good team. I added two surreptitious edits to my apache2.conf file to mitigate slow and low attacks. Change these values from 5 minutes to 3.

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 180
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 3

It’s also ok for us to limit the types of requests that our webserver will work with:

# Only allow POST and GET requests.
<LimitExcept POST GET>
     Deny from all
</LimitExcept>

I still edited the virtual host config files myself, although Claude could have done that for me as well. Check out the finished hardened Apache virtual host config for a Drupal 10 or 11 site here.

I like to pull my weight in any relationship. Also, Claude needs some oversight and scoping at times. They are dilligent, nonetheless.

I think I will leave work early today.

Image of a padlock with the drupal drop face superimposed on it.