Readable .htaccess file

  • CWE 425
  • WASC 34

Readable .htaccess files occur when Apache or compatible web server configuration files are publicly accessible. .htaccess files often contain directives for URL rewriting, authentication, access control, and security policies. If exposed, attackers can gain insight into server configuration, directory structures, authentication mechanisms, and potentially sensitive paths. This information can be leveraged to craft targeted attacks, bypass security controls, or identify misconfigurations.

Common patterns leading to readable .htaccess exposure:

  • Uploading .htaccess files to web root without restricting public access.
  • Misconfigured web server rules that serve .htaccess as regular text files.
  • Including .htaccess in version control or deployment pipelines without proper exclusion.
  • Lack of server directives to hide or deny access to dotfiles.

Impacts:

  • Information Disclosure: Reveals server configuration, authentication methods, and sensitive paths.
  • Facilitates Targeted Attacks: Attackers can use configuration details to exploit security weaknesses or bypass access controls.
  • Increased Attack Surface: Knowledge of rewrite rules, directory structure, or authentication policies aids exploitation.
  • Reconnaissance Aid: Exposure helps attackers understand server behavior and design attacks accordingly.

Detection indicators:

  • .htaccess files accessible via direct HTTP requests.
  • Web server serving .htaccess content instead of denying access.
  • Security scanners flagging publicly readable dotfiles.
Remediation

Mitigation focuses on restricting access and securing deployment:

  1. Deny Public Access to .htaccess
    Configure the web server to block HTTP requests for .htaccess and other dotfiles.

  2. Move Sensitive Configuration Files Outside Web Root
    Where feasible, keep configuration files outside of web-accessible directories.

  3. Review Deployment Pipelines
    Ensure .htaccess files are deployed with correct permissions and access restrictions.

  4. Use Proper File Permissions
    Limit file read access to the web server user and authorized administrators.

  5. Monitor and Audit Web Server Access
    Track attempts to access .htaccess or other sensitive configuration files.

  6. Security Testing
    Include checks for dotfiles exposure in penetration testing and automated scans.

  7. Educate Developers and Administrators
    Ensure team members understand the risks of exposing configuration files publicly.

References