| @@ -31,8 +31,6 @@ enableForwardedWhitelist: true | ||
| 31 | 31 | whitelist: |
| 32 | 32 | - ::1 |
| 33 | 33 | - 127.0.0.1 |
| 34 | -# HTML displayed when a connection is blocked. Use "{{ipDetails}}" to print the client's IP. | |
| 35 | -whitelistErrorMessage: "<h1>Forbidden</h1><p>If you are the system administrator, add your IP address to the whitelist or disable whitelist mode by editing <code>config.yaml</code> in the root directory of your installation.</p><hr /><p><em>Connection from {{ipDetails}} has been blocked. This attempt has been logged.</em></p>" | |
| 36 | 34 | # Toggle basic authentication for endpoints |
| 37 | 35 | basicAuthMode: false |
| 38 | 36 | # Basic authentication credentials |
| @@ -0,0 +1,22 @@ | ||
| 1 | +<!DOCTYPE html> | |
| 2 | +<html> | |
| 3 | + | |
| 4 | +<head> | |
| 5 | + <title>Forbidden</title> | |
| 6 | +</head> | |
| 7 | + | |
| 8 | +<body> | |
| 9 | + <h1>Forbidden</h1> | |
| 10 | + <p> | |
| 11 | + If you are the system administrator, add your IP address to the | |
| 12 | + whitelist or disable whitelist mode by editing | |
| 13 | + <code>config.yaml</code> in the root directory of your installation. | |
| 14 | + </p> | |
| 15 | + <hr /> | |
| 16 | + <p> | |
| 17 | + <em>Connection from {{ipDetails}} has been blocked. This attempt | |
| 18 | + has been logged.</em> | |
| 19 | + </p> | |
| 20 | +</body> | |
| 21 | + | |
| 22 | +</html> | |
| @@ -11,16 +11,7 @@ const whitelistPath = path.join(process.cwd(), './whitelist.txt'); | ||
| 11 | 11 | const enableForwardedWhitelist = getConfigValue('enableForwardedWhitelist', false); |
| 12 | 12 | let whitelist = getConfigValue('whitelist', []); |
| 13 | 13 | let knownIPs = new Set(); |
| 14 | - | |
| 14 | +const forbiddenWebpage = Handlebars.compile(fs.readFileSync('./public/error/forbidden-by-whitelist.html', 'utf-8')); | |
| 15 | -const DEFAULT_WHITELIST_ERROR_MESSAGE = | |
| 16 | - '<h1>Forbidden</h1><p>If you are the system administrator, add your IP address to the whitelist or disable whitelist mode by editing <code>config.yaml</code> in the root directory of your installation.</p><hr /><p><em>Connection from {{ipDetails}} has been blocked. This attempt has been logged.</em></p>'; | |
| 17 | - | |
| 18 | -const errorMessage = Handlebars.compile( | |
| 19 | - getConfigValue( | |
| 20 | - 'whitelistErrorMessage', | |
| 21 | - DEFAULT_WHITELIST_ERROR_MESSAGE, | |
| 22 | - ), | |
| 23 | -); | |
| 24 | 15 | |
| 25 | 16 | if (fs.existsSync(whitelistPath)) { |
| 26 | 17 | try { |
| @@ -95,7 +86,7 @@ export default function whitelistMiddleware(whitelistMode, listen) { | ||
| 95 | 86 | `Blocked connection from ${clientIp}; User Agent: ${userAgent}\n\tTo allow this connection, add its IP address to the whitelist or disable whitelist mode by editing config.yaml in the root directory of your SillyTavern installation.\n`, |
| 96 | 87 | ), |
| 97 | 88 | ); |
| 98 | 89 | return res.status(403).send(errorMessageforbiddenWebpage({ ipDetails })); |
| 99 | 90 | } |
| 100 | 91 | next(); |
| 101 | 92 | }; |