|
| 1 | +# PHP Terminal - Security Configuration |
| 2 | +# Apache .htaccess file for enhanced security |
| 3 | + |
| 4 | +# Disable server signature |
| 5 | +ServerSignature Off |
| 6 | + |
| 7 | +# Hide Apache version |
| 8 | +<IfModule mod_headers.c> |
| 9 | + Header unset Server |
| 10 | + Header always unset X-Powered-By |
| 11 | + Header unset X-Powered-By |
| 12 | + Header unset X-CF-Powered-By |
| 13 | + Header unset X-Mod-Pagespeed |
| 14 | + Header unset X-Pingback |
| 15 | +</IfModule> |
| 16 | + |
| 17 | +# Security Headers |
| 18 | +<IfModule mod_headers.c> |
| 19 | + # Prevent MIME type sniffing |
| 20 | + Header always set X-Content-Type-Options nosniff |
| 21 | + |
| 22 | + # Enable XSS filtering |
| 23 | + Header always set X-XSS-Protection "1; mode=block" |
| 24 | + |
| 25 | + # Prevent clickjacking |
| 26 | + Header always set X-Frame-Options DENY |
| 27 | + |
| 28 | + # Strict Transport Security (HTTPS only) |
| 29 | + Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" |
| 30 | + |
| 31 | + # Content Security Policy |
| 32 | + Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-ancestors 'none';" |
| 33 | + |
| 34 | + # Referrer Policy |
| 35 | + Header always set Referrer-Policy "strict-origin-when-cross-origin" |
| 36 | + |
| 37 | + # Permissions Policy |
| 38 | + Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()" |
| 39 | +</IfModule> |
| 40 | + |
| 41 | +# Disable directory browsing |
| 42 | +Options -Indexes |
| 43 | + |
| 44 | +# Follow symbolic links |
| 45 | +Options +FollowSymLinks |
| 46 | + |
| 47 | +# Disable server signature |
| 48 | +ServerTokens Prod |
| 49 | + |
| 50 | +# Prevent access to sensitive files |
| 51 | +<FilesMatch "\.(env|log|sql|bak|backup|old|orig|tmp)$"> |
| 52 | + Order allow,deny |
| 53 | + Deny from all |
| 54 | +</FilesMatch> |
| 55 | + |
| 56 | +# Protect configuration files |
| 57 | +<FilesMatch "^(config|\.env|\.htaccess|\.htpasswd)"> |
| 58 | + Order allow,deny |
| 59 | + Deny from all |
| 60 | +</FilesMatch> |
| 61 | + |
| 62 | +# Protect cache and logs directories |
| 63 | +<DirectoryMatch "^(cache|logs|uploads)/"> |
| 64 | + Order allow,deny |
| 65 | + Deny from all |
| 66 | +</DirectoryMatch> |
| 67 | + |
| 68 | +# Prevent access to PHP files in media directory |
| 69 | +<Directory "media/"> |
| 70 | + <Files "*.php"> |
| 71 | + Order allow,deny |
| 72 | + Deny from all |
| 73 | + </Files> |
| 74 | +</Directory> |
| 75 | + |
| 76 | +# Limit file upload size |
| 77 | +php_value upload_max_filesize 10M |
| 78 | +php_value post_max_size 20M |
| 79 | +php_value max_execution_time 30 |
| 80 | +php_value max_input_time 30 |
| 81 | +php_value memory_limit 128M |
| 82 | + |
| 83 | +# Disable dangerous PHP functions |
| 84 | +php_value disable_functions "exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source" |
| 85 | + |
| 86 | +# Enable error logging |
| 87 | +php_value log_errors On |
| 88 | +php_value error_log /var/log/phpterminal.log |
| 89 | + |
| 90 | +# Disable display of errors in production |
| 91 | +php_value display_errors Off |
| 92 | +php_value display_startup_errors Off |
| 93 | + |
| 94 | +# Enable session security |
| 95 | +php_value session.cookie_httponly 1 |
| 96 | +php_value session.cookie_secure 1 |
| 97 | +php_value session.use_only_cookies 1 |
| 98 | +php_value session.cookie_samesite Strict |
| 99 | + |
| 100 | +# Prevent access to version control files |
| 101 | +<FilesMatch "\.(git|svn|hg)"> |
| 102 | + Order allow,deny |
| 103 | + Deny from all |
| 104 | +</FilesMatch> |
| 105 | + |
| 106 | +# Rate limiting (if mod_evasive is available) |
| 107 | +<IfModule mod_evasive24.c> |
| 108 | + DOSHashTableSize 2048 |
| 109 | + DOSPageCount 3 |
| 110 | + DOSPageInterval 1 |
| 111 | + DOSSiteCount 50 |
| 112 | + DOSSiteInterval 1 |
| 113 | + DOSBlockingPeriod 600 |
| 114 | +</IfModule> |
| 115 | + |
| 116 | +# Compression for better performance |
| 117 | +<IfModule mod_deflate.c> |
| 118 | + AddOutputFilterByType DEFLATE text/plain |
| 119 | + AddOutputFilterByType DEFLATE text/html |
| 120 | + AddOutputFilterByType DEFLATE text/xml |
| 121 | + AddOutputFilterByType DEFLATE text/css |
| 122 | + AddOutputFilterByType DEFLATE application/xml |
| 123 | + AddOutputFilterByType DEFLATE application/xhtml+xml |
| 124 | + AddOutputFilterByType DEFLATE application/rss+xml |
| 125 | + AddOutputFilterByType DEFLATE application/javascript |
| 126 | + AddOutputFilterByType DEFLATE application/x-javascript |
| 127 | +</IfModule> |
| 128 | + |
| 129 | +# Browser caching |
| 130 | +<IfModule mod_expires.c> |
| 131 | + ExpiresActive On |
| 132 | + ExpiresByType text/css "access plus 1 month" |
| 133 | + ExpiresByType application/javascript "access plus 1 month" |
| 134 | + ExpiresByType image/png "access plus 1 month" |
| 135 | + ExpiresByType image/jpg "access plus 1 month" |
| 136 | + ExpiresByType image/jpeg "access plus 1 month" |
| 137 | + ExpiresByType image/gif "access plus 1 month" |
| 138 | + ExpiresByType image/svg+xml "access plus 1 month" |
| 139 | + ExpiresByType font/woff "access plus 1 month" |
| 140 | + ExpiresByType font/woff2 "access plus 1 month" |
| 141 | +</IfModule> |
| 142 | + |
| 143 | +# Force HTTPS (uncomment in production) |
| 144 | +# RewriteEngine On |
| 145 | +# RewriteCond %{HTTPS} off |
| 146 | +# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
| 147 | + |
| 148 | +# Custom error pages |
| 149 | +ErrorDocument 404 /phpterminal.php |
| 150 | +ErrorDocument 403 /phpterminal.php |
| 151 | +ErrorDocument 500 /phpterminal.php |
0 commit comments