Use cURL for Bluesky API calls instead of file_get_contents
CI / test (pull_request) Successful in 40s
CI / test (pull_request) Successful in 40s
FreshRSS 1.30.0 added unregister_unsafe_protocols() to lib/lib_rss.php, which unregisters every PHP stream wrapper except file:// and php:// at boot as an SSRF mitigation. That removed the https:// wrapper, so the stream-context-based fetch in apiGet() stopped working entirely — every API call failed with "Unable to find the wrapper https". Because the call site used @file_get_contents(), the failure was silent: apiGet() returned null, loadThread() fell through to its null fallback, and entries were saved with their unenriched RSS content. The visible symptom was Bluesky posts rendering with no thread and no embeds, with nothing in the logs to explain it. Switch apiGet() to cURL, which does not go through stream wrappers (and is how FreshRSS fetches feeds itself, which is why feed retrieval kept working throughout). Connect timeout added and redirect-following explicitly disabled — a public XRPC endpoint has no reason to redirect, and following redirects would reopen an SSRF vector. Also stop swallowing failures: transport errors, non-2xx responses and malformed JSON are now reported via Minz_Log::warning() so this class of breakage is visible next time. Tests: add testApiGetWorksWithoutHttpsStreamWrapper, which unregisters the https wrapper before calling the API and so fails against the old implementation, plus testApiGetLogsWarningOnFailure. Add a Minz_Log stub and curl to the CI extension list. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -20,6 +20,7 @@ class BlueskyThreadsTest extends TestCase {
|
||||
|
||||
protected function setUp(): void {
|
||||
Minz_Request::reset();
|
||||
Minz_Log::reset();
|
||||
$this->ext = new BlueskyThreadsExtension();
|
||||
}
|
||||
|
||||
@@ -323,4 +324,49 @@ class BlueskyThreadsTest extends TestCase {
|
||||
|
||||
$this->assertSame(1000, $this->ext->getUserConfigurationValue('depth'));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// API transport — must not depend on PHP stream wrappers
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Regression test for the FreshRSS 1.30.0 breakage.
|
||||
*
|
||||
* 1.30.0 unregisters every stream wrapper except file:// and php:// at
|
||||
* boot as an SSRF mitigation, which silently killed the previous
|
||||
* file_get_contents()-based fetch. We reproduce that exact condition and
|
||||
* assert apiGet() still reaches the API.
|
||||
*/
|
||||
public function testApiGetWorksWithoutHttpsStreamWrapper(): void {
|
||||
if (!in_array('https', stream_get_wrappers(), true)) {
|
||||
$this->markTestSkipped('No https stream wrapper registered in this PHP build.');
|
||||
}
|
||||
|
||||
stream_wrapper_unregister('https');
|
||||
try {
|
||||
$data = $this->call('apiGet', 'com.atproto.identity.resolveHandle', ['handle' => 'hockeyviz.com']);
|
||||
} finally {
|
||||
stream_wrapper_restore('https');
|
||||
}
|
||||
|
||||
if ($data === null) {
|
||||
$this->markTestSkipped('Bluesky API unreachable: ' . implode('; ', Minz_Log::messages()));
|
||||
}
|
||||
|
||||
$this->assertSame('did:plc:d4324t32vfi5xzydqbh2qdj3', $data['did'] ?? null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A failed API call must return null *and* leave a trace in the log.
|
||||
* The original code suppressed errors with @, so this whole failure mode
|
||||
* was invisible for a day. Passes online (bogus method → HTTP 4xx) and
|
||||
* offline (connection error) alike.
|
||||
*/
|
||||
public function testApiGetLogsWarningOnFailure(): void {
|
||||
$data = $this->call('apiGet', 'com.example.doesNotExist', []);
|
||||
|
||||
$this->assertNull($data);
|
||||
$this->assertNotEmpty(Minz_Log::messages(), 'A failed API call must be logged.');
|
||||
$this->assertStringContainsString('[BlueskyThreads]', Minz_Log::messages()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,3 +78,25 @@ class Minz_Request {
|
||||
self::$params = [];
|
||||
}
|
||||
}
|
||||
|
||||
class Minz_Log {
|
||||
/** @var list<string> */
|
||||
private static array $messages = [];
|
||||
|
||||
public static function warning(string $message): void {
|
||||
self::$messages[] = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test helper: all warnings recorded since the last reset().
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
public static function messages(): array {
|
||||
return self::$messages;
|
||||
}
|
||||
|
||||
public static function reset(): void {
|
||||
self::$messages = [];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user