feat(onebot): download stream actions (#163 phase 3)
NapCat-compatible server-push download: one request answered by a file_info header, N base64 file_chunk frames, then a terminal file_complete. Bytes come from a local file under the stream temp root, an http(s) URL, or a cached image/voice id resolved to its QQ CDN URL. test_download_stream pushes 10 canned frames so a client can validate the transport without touching QQ. Actions: download_file_stream / download_file_image_stream / download_file_record_stream / test_download_stream. Hardened beyond the NapCat original (which streams any local path and follows redirects to anywhere), per three adversarial review passes: - arbitrary-file-read: local reads are fenced inside the stream temp root, realpath-resolved so a symlink can't point out. - SSRF: every URL (incl. each redirect hop, followed manually) is guarded — http(s) only, and neither the literal host nor any resolved address may be private/loopback/link-local; IPv6 is byte-parsed so normalized v4-mapped literals (::ffff:a9fe:a9fe) can't slip past. (DNS rebinding remains a documented residual — needs connect-time peer-IP validation.) - robustness: TTFB-only connect timeout (doesn't cut a large body mid-stream) plus a per-chunk idle watchdog that aborts a stalled source so a hung upstream can't pin a socket; total size capped; non-2xx bodies cancelled; client disconnect aborts via the sink. 501 onebot tests green.
This commit is contained in:
4 files changed
+498
-1
No files matched your search
@@ -12,6 +12,7 @@ import { register as registerMessage } from './actions/message';
|
||||
import { register as registerQzone } from './actions/qzone';
|
||||
import { register as registerRequest } from './actions/request';
|
||||
import { register as registerStreamFile } from './actions/stream-file';
|
||||
import { register as registerStreamDownload } from './actions/stream-download';
|
||||
import type { ForwardPreviewMeta } from './modules/message-actions';
|
||||
import type { JsonObject, JsonValue, MessageMeta } from './types';
|
||||
import { RETCODE, failedResponse } from './types';
|
||||
@@ -122,6 +123,7 @@ export class ApiHandler {
|
||||
registerGroupAlbum(this, context);
|
||||
registerQzone(this, context);
|
||||
registerStreamFile(this, context);
|
||||
registerStreamDownload(this, context);
|
||||
}
|
||||
|
||||
registerAction(action: string, handler: ActionHandler): void {
|
||||
|
||||
Reference in new issue
Block a user