1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-10 02:26:37 +02:00

fix: introduce system env var, remove debug mode (#4658)

* fix: introduce system env var

* docs

* docs
This commit is contained in:
Dag
2025-08-08 01:38:12 +02:00
committed by GitHub
parent a128c05a97
commit 81ce9c9483
12 changed files with 55 additions and 95 deletions

View File

@@ -369,14 +369,6 @@ enabled_bridges[] = TwitchBridge
enabled_bridges[] = GettrBridge enabled_bridges[] = GettrBridge
``` ```
### How to enable debug mode
The
[debug mode](https://rss-bridge.github.io/rss-bridge/For_Developers/Debug_mode.html)
disables the majority of caching operations.
enable_debug_mode = true
### How to switch to memcached as cache backend ### How to switch to memcached as cache backend
``` ```

View File

@@ -22,8 +22,8 @@ class ConnectivityAction implements ActionInterface
public function __invoke(Request $request): Response public function __invoke(Request $request): Response
{ {
if (!Debug::isEnabled()) { if (Configuration::getConfig('system', 'env') !== 'dev') {
return new Response('This action is only available in debug mode!', 403); return new Response('This action is only available in dev environment!', 403);
} }
$bridgeName = $request->get('bridge'); $bridgeName = $request->get('bridge');

View File

@@ -178,10 +178,8 @@ class BlueskyBridge extends BridgeAbstract
$postDisplayName = e($postDisplayName); $postDisplayName = e($postDisplayName);
$postUri = $item['uri']; $postUri = $item['uri'];
if (Debug::isEnabled()) { $url = explode('/', $post['post']['uri']);
$url = explode('/', $post['post']['uri']); $this->logger->debug('https://bsky.app/profile/' . $url[2] . '/post/' . $url[4]);
$this->logger->debug('https://bsky.app/profile/' . $url[2] . '/post/' . $url[4]);
}
$description = ''; $description = '';
$description .= '<p>'; $description .= '<p>';
@@ -612,9 +610,9 @@ class BlueskyBridge extends BridgeAbstract
private function getAuthorFeed($did, $filter) private function getAuthorFeed($did, $filter)
{ {
$uri = 'https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor=' . urlencode($did) . '&filter=' . urlencode($filter) . '&limit=30'; $uri = 'https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor=' . urlencode($did) . '&filter=' . urlencode($filter) . '&limit=30';
if (Debug::isEnabled()) {
$this->logger->debug($uri); $this->logger->debug($uri);
}
$response = json_decode(getContents($uri), true); $response = json_decode(getContents($uri), true);
return $response; return $response;
} }

View File

@@ -6,6 +6,9 @@
[system] [system]
; System environment: "dev" or "prod"
env = "prod"
; Only these bridges are available for feed production ; Only these bridges are available for feed production
; How to enable all bridges: enabled_bridges[] = * ; How to enable all bridges: enabled_bridges[] = *
;enabled_bridges[] = CssSelectorBridge ;enabled_bridges[] = CssSelectorBridge
@@ -31,13 +34,6 @@ timezone = "UTC"
; Display a system message to users. ; Display a system message to users.
;message = "Hello world" ;message = "Hello world"
; Whether to enable debug mode.
enable_debug_mode = false
; Enable debug mode only for these permitted ip addresses
; debug_mode_whitelist[] = 127.0.0.1
; debug_mode_whitelist[] = 192.168.1.10
; Whether to enable maintenance mode. If enabled, feed requests receive 503 Service Unavailable ; Whether to enable maintenance mode. If enabled, feed requests receive 503 Service Unavailable
enable_maintenance_mode = false enable_maintenance_mode = false

View File

@@ -1,23 +1,28 @@
<h1 align="center">Warning!</h1> Debug mode has been removed.
Enabling debug mode on a public server may result in malicious clients retrieving sensitive data about your server and possibly gaining access to it. If you want to disable caching you can set cache type to array (in-memory cache):
Do not enable debug mode on a public server, unless you understand the implications of your doing!
*** ```ini
[cache]
Debug mode enables error reporting and prevents loading data from the cache (data is still written to the cache). ; Cache type: file, sqlite, memcached, array, null
To enable debug mode, set in `config.ini.php`: type = "array"
```
enable_debug_mode = true Alternatively, you can comment out the cache middleware in `lib/RssBridge.php`:
Allow only explicit ip addresses: ```diff
diff --git a/lib/RssBridge.php b/lib/RssBridge.php
index d16f1d89..da3df8be 100644
--- a/lib/RssBridge.php
+++ b/lib/RssBridge.php
@@ -24,7 +24,7 @@ final class RssBridge
debug_mode_whitelist[] = 127.0.0.1 $middlewares = [
debug_mode_whitelist[] = 192.168.1.10 new BasicAuthMiddleware(),
- new CacheMiddleware($this->container['cache']),
_Notice_: + //new CacheMiddleware($this->container['cache']),
new ExceptionMiddleware($this->container['logger']),
* An empty file enables debug mode for anyone! new SecurityMiddleware(),
* The bridge whitelist still applies! (debug mode does **not** enable all bridges) new MaintenanceMiddleware(),
```
RSS-Bridge will give you a visual feedback when debug mode is enabled.

View File

@@ -6,7 +6,6 @@ If you are new to **RSS-Bridge** you should make yourself familiar with some gen
- [Coding style policy](./01_Coding_style_policy.md) - [Coding style policy](./01_Coding_style_policy.md)
- [Folder structure](./03_Folder_structure.md) - [Folder structure](./03_Folder_structure.md)
- [Debug mode](./05_Debug_mode.md)
- [Bridge API](../05_Bridge_API/index.md) - [Bridge API](../05_Bridge_API/index.md)
- [Cache API](../07_Cache_API/index.md) - [Cache API](../07_Cache_API/index.md)
- [Technical recommendations](../09_Technical_recommendations/index.md) - [Technical recommendations](../09_Technical_recommendations/index.md)

View File

@@ -29,7 +29,7 @@ set_error_handler(function ($code, $message, $file, $line) use ($logger) {
// Deprecation messages and other masked errors are typically ignored here // Deprecation messages and other masked errors are typically ignored here
return false; return false;
} }
if (Debug::isEnabled()) { if (Configuration::getConfig('system', 'env') === 'dev') {
// This might be annoying, but it's for the greater good // This might be annoying, but it's for the greater good
throw new \ErrorException($message, 0, $code, $file, $line); throw new \ErrorException($message, 0, $code, $file, $line);
} }

View File

@@ -36,11 +36,10 @@ final class Configuration
} }
if (file_exists(__DIR__ . '/../DEBUG')) { if (file_exists(__DIR__ . '/../DEBUG')) {
// The debug mode has been moved to config. Preserve existing installs which has this DEBUG file.
self::setConfig('system', 'enable_debug_mode', true);
$debug = trim(file_get_contents(__DIR__ . '/../DEBUG')); $debug = trim(file_get_contents(__DIR__ . '/../DEBUG'));
if ($debug) { if ($debug === '') {
self::setConfig('system', 'debug_mode_whitelist', explode("\n", str_replace("\r", '', $debug))); self::setConfig('system', 'env', 'dev');
self::setConfig('cache', 'type', 'array');
} }
} }
@@ -82,8 +81,8 @@ final class Configuration
} }
} }
if (Debug::isEnabled()) { if (!in_array(self::getConfig('system', 'env'), ['dev', 'prod'])) {
self::setConfig('cache', 'type', 'array'); self::throwConfigError('system', 'env', 'Must be dev or prod');
} }
if (!is_array(self::getConfig('system', 'enabled_bridges'))) { if (!is_array(self::getConfig('system', 'enabled_bridges'))) {
@@ -97,13 +96,6 @@ final class Configuration
self::throwConfigError('system', 'timezone'); self::throwConfigError('system', 'timezone');
} }
if (!is_bool(self::getConfig('system', 'enable_debug_mode'))) {
self::throwConfigError('system', 'enable_debug_mode', 'Is not a valid Boolean');
}
if (!is_array(self::getConfig('system', 'debug_mode_whitelist') ?: [])) {
self::throwConfigError('system', 'debug_mode_whitelist', 'Is not a valid array');
}
if (!is_string(self::getConfig('proxy', 'url'))) { if (!is_string(self::getConfig('proxy', 'url'))) {
self::throwConfigError('proxy', 'url', 'Is not a valid string'); self::throwConfigError('proxy', 'url', 'Is not a valid string');
} }
@@ -199,6 +191,8 @@ final class Configuration
private static function throwConfigError($section, $key, $message = '') private static function throwConfigError($section, $key, $message = '')
{ {
throw new \Exception("Config [$section] => [$key] is invalid. $message"); http_response_code(500);
print ("Config [$section] => [$key] is invalid. $message");
exit(1);
} }
} }

View File

@@ -1,18 +0,0 @@
<?php
class Debug
{
/**
* Convenience function for Configuration::getConfig('system', 'enable_debug_mode')
*/
public static function isEnabled(): bool
{
$ip = $_SERVER['REMOTE_ADDR'] ?? 'x.y.z.1';
$enableDebugMode = Configuration::getConfig('system', 'enable_debug_mode');
$debugModeWhitelist = Configuration::getConfig('system', 'debug_mode_whitelist') ?: [];
if ($enableDebugMode && ($debugModeWhitelist === [] || in_array($ip, $debugModeWhitelist))) {
return true;
}
return false;
}
}

View File

@@ -47,16 +47,16 @@ $container['cache_factory'] = function ($c) {
$container['logger'] = function () { $container['logger'] = function () {
$logger = new SimpleLogger('rssbridge'); $logger = new SimpleLogger('rssbridge');
if (Debug::isEnabled()) { if (Configuration::getConfig('system', 'env') === 'dev') {
$logger->addHandler(new ErrorLogHandler(Logger::DEBUG)); $logger->addHandler(new ErrorLogHandler(Logger::DEBUG));
} else { } else {
$logger->addHandler(new ErrorLogHandler(Logger::INFO)); $logger->addHandler(new ErrorLogHandler(Logger::INFO));
} }
// Uncomment this for info logging to fs // Uncomment this for info logging to fs
// $logger->addHandler(new StreamHandler('/tmp/rss-bridge.txt', Logger::INFO)); // $logger->addHandler(new StreamHandler('/tmp/rss-bridge.log', Logger::INFO));
// Uncomment this for debug logging to fs // Uncomment this for debug logging to fs
// $logger->addHandler(new StreamHandler('/tmp/rss-bridge-debug.txt', Logger::DEBUG)); // $logger->addHandler(new StreamHandler('/tmp/rss-bridge-debug.log', Logger::DEBUG));
return $logger; return $logger;
}; };

View File

@@ -15,19 +15,15 @@ function render(string $template, array $context = []): string
'level' => 'info', 'level' => 'info',
]; ];
} }
if (Debug::isEnabled()) { if (Configuration::getConfig('system', 'env') === 'dev') {
$debugModeWhitelist = Configuration::getConfig('system', 'debug_mode_whitelist') ?: []; $context['messages'][] = [
if ($debugModeWhitelist === []) { 'body' => 'System environment: dev',
$context['messages'][] = [ 'level' => 'error'
'body' => 'Warning : Debug mode is active from any location, make sure only you can access RSS-Bridge.', ];
'level' => 'error' $context['messages'][] = [
]; 'body' => sprintf('Cache type: %s', Configuration::getConfig('cache', 'type')),
} else { 'level' => 'info'
$context['messages'][] = [ ];
'body' => 'Warning : Debug mode is active from your IP address, your requests will bypass the cache.',
'level' => 'warning'
];
}
} }
$context['page'] = render_template($template, $context); $context['page'] = render_template($template, $context);
return render_template('base.html.php', $context); return render_template('base.html.php', $context);

View File

@@ -23,12 +23,10 @@ class HttpException extends \Exception
public static function fromResponse(Response $response, string $url): HttpException public static function fromResponse(Response $response, string $url): HttpException
{ {
$message = sprintf( $message = sprintf(
'%s resulted in %s %s %s', '%s resulted in %s %s',
$url, $url,
$response->getCode(), $response->getCode(),
$response->getStatusLine(), $response->getStatusLine()
// If debug, include a part of the response body in the exception message
Debug::isEnabled() ? mb_substr($response->getBody(), 0, 500) : '',
); );
if (CloudFlareException::isCloudFlareResponse($response)) { if (CloudFlareException::isCloudFlareResponse($response)) {
return new CloudFlareException($message, $response->getCode(), $response); return new CloudFlareException($message, $response->getCode(), $response);