fix(onebot): protect managed stream storage
Validate managed storage before stream files are created, read, or cleaned, and reject unsafe local directory state without changing the public stream actions. Keep ordinary existing installations compatible and add regression coverage for startup, runtime replacement, ownership, permissions, and normal transfer behavior.
This commit is contained in:
4 files changed
+127
-22
No files matched your search
@@ -26,7 +26,11 @@ import { defineStreamAction, f } from '../action-kit';
|
||||
import type { ApiActionContext } from '../api-handler';
|
||||
import { okResponse, type ApiResponse, type JsonObject, type JsonValue } from '../types';
|
||||
import { type StreamSink, StreamStatus } from '../streaming';
|
||||
import { STREAM_ROOT, registerActiveStreamItem } from '../stream-storage';
|
||||
import {
|
||||
STREAM_ROOT,
|
||||
ensureStreamDirectory,
|
||||
registerActiveStreamItem,
|
||||
} from '../stream-storage';
|
||||
|
||||
const DEFAULT_CHUNK_BYTES = 64 * 1024;
|
||||
const MAX_CHUNK_REQUEST_BYTES = 16 * 1024 * 1024; // cap the client-requested chunk size
|
||||
@@ -224,6 +228,7 @@ async function resolveDownload(
|
||||
let st: fs.Stats | null = null;
|
||||
try { st = fs.statSync(local); } catch { st = null; }
|
||||
if (st?.isFile()) {
|
||||
ensureStreamDirectory(STREAM_ROOT);
|
||||
// Fence against the *real* path so a symlink inside the root can't point
|
||||
// out (lexical resolve alone would follow it).
|
||||
let real = local;
|
||||
|
||||
@@ -30,6 +30,7 @@ import {
|
||||
STREAM_ROOT,
|
||||
STREAM_UPLOAD_DIR,
|
||||
clearInactiveStreamStorage,
|
||||
ensureStreamDirectory,
|
||||
registerActiveStreamItem,
|
||||
} from '../stream-storage';
|
||||
|
||||
@@ -149,7 +150,7 @@ function createUpload(p: UploadParams, account: string): UploadState {
|
||||
const finalPath = path.join(dirRoot, `${p.stream_id}__${filename}`);
|
||||
assertWithin(STREAM_UPLOAD_DIR, tempDir);
|
||||
assertWithin(STREAM_UPLOAD_DIR, finalPath);
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
ensureStreamDirectory(tempDir);
|
||||
|
||||
const key = account ? `${account}:${p.stream_id}` : p.stream_id;
|
||||
const releaseStorageActivity = registerActiveStreamItem([tempDir, finalPath]);
|
||||
|
||||
Reference in new issue
Block a user