ekke 664c242980 Apache hardening: block .git and .env disclosure
Preventive, not incident-driven. No LUPMIS host is known to have been
compromised; these rules exist so the most common automated attack against a
PHP deployment cannot succeed.

Scanners probe every public host for /.env (database passwords, API keys) and
/.git/. The second is the more damaging: given /.git/index together with
/.git/objects an attacker can reconstruct the whole repository, including its
history — so any credential ever committed is exposed even after rotation.
That is directly relevant here, because the minio-uploads integration has had
access keys written into its PHP files and those files are tracked in Gitea.

- public/.htaccess: deny hidden paths and files that should never be served.
- docs/apache-hardening.conf: the same rules for vhost/server config, which is
  where they belong — .htaccess depends on AllowOverride. Also covers logging
  the real client address through the openresty proxy (mod_remoteip), and
  blocking at the proxy so requests never reach the application.

Two details that are easy to get wrong, and are handled:

- <FilesMatch "^\."> does NOT stop /.git/config. FilesMatch tests the basename
  only, and there the basename is "config". Blocking a hidden directory needs a
  rule that sees the whole path: mod_rewrite in .htaccess, <DirectoryMatch> in
  server config.
- The SPA fallback only rewrites paths that do not exist (!-f), so a real .env
  on disk skips it and is served as a plain file. The deny rules therefore run
  before the fallback, not after.

.well-known is exempt, or ACME certificate renewal would silently break.

Verified against a live Apache instance with a planted .env and .git tree:
/.env and /./.env return 403; /.git/config, /.git/HEAD, /.git/objects/... and
/backup.sql return 404; /.well-known/acme-challenge/..., /assets/*.js and
/manifest.json still return 200. Nothing in the document root is caught — the
only dotfile there is .htaccess, which Apache never serves.

These rules are damage limitation. The fix is to keep .git and .env out of a
document root: deploy build output rather than a working copy, and hold secrets
in environment variables outside the served tree.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-11 12:53:20 +02:00
..
2026-03-04 12:59:40 +01:00