@adep/runtime 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +26 -24
- package/dist/storage/driver/s3.d.ts +1 -0
- package/dist/storage/driver.d.ts +9 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1207,6 +1207,19 @@ function assertSafeStoragePath(path) {
|
|
|
1207
1207
|
}
|
|
1208
1208
|
return path;
|
|
1209
1209
|
}
|
|
1210
|
+
function assertStoragePrefix(prefix) {
|
|
1211
|
+
if (prefix !== void 0 && prefix !== "") {
|
|
1212
|
+
const segments = prefix.split("/");
|
|
1213
|
+
if (prefix.startsWith("/") || /[\\]/.test(prefix) || segments.some((segment) => segment === "..")) {
|
|
1214
|
+
throw new StorageError(
|
|
1215
|
+
400,
|
|
1216
|
+
STORAGE_CODES.invalidPath,
|
|
1217
|
+
`\u975E\u6CD5\u524D\u7F00 "${prefix}"\uFF08\u7981\u6B62 / \u5F00\u5934\u3001\u53CD\u659C\u6760\u6216 .. \u7A7F\u8D8A\uFF09`
|
|
1218
|
+
);
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
return prefix ?? "";
|
|
1222
|
+
}
|
|
1210
1223
|
|
|
1211
1224
|
// packages/runtime/src/storage/hmac-sha256.ts
|
|
1212
1225
|
var K = new Uint32Array([
|
|
@@ -1614,16 +1627,7 @@ function createLocalStorageDriver(options) {
|
|
|
1614
1627
|
await unlink(metaPath(projectId, path)).catch(() => void 0);
|
|
1615
1628
|
},
|
|
1616
1629
|
async list(projectId, prefix) {
|
|
1617
|
-
|
|
1618
|
-
const segments = prefix.split("/");
|
|
1619
|
-
if (prefix.startsWith("/") || /[\\]/.test(prefix) || segments.some((segment) => segment === "..")) {
|
|
1620
|
-
throw new StorageError(
|
|
1621
|
-
400,
|
|
1622
|
-
STORAGE_CODES.invalidPath,
|
|
1623
|
-
`\u975E\u6CD5\u524D\u7F00 "${prefix}"\uFF08\u7981\u6B62 / \u5F00\u5934\u3001\u53CD\u659C\u6760\u6216 .. \u7A7F\u8D8A\uFF09`
|
|
1624
|
-
);
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1630
|
+
assertStoragePrefix(prefix);
|
|
1627
1631
|
const root = bucketDir(projectId);
|
|
1628
1632
|
const metas = [];
|
|
1629
1633
|
const walk = async (dir, relative) => {
|
|
@@ -1803,19 +1807,6 @@ var mapError = async (res, message) => {
|
|
|
1803
1807
|
`\u5BF9\u8C61\u5B58\u50A8\u540E\u7AEF\u9519\u8BEF\uFF08HTTP ${res.status} ${code || ""}\uFF09\uFF1A${message}`
|
|
1804
1808
|
);
|
|
1805
1809
|
};
|
|
1806
|
-
var assertPrefix = (prefix) => {
|
|
1807
|
-
if (prefix !== void 0 && prefix !== "") {
|
|
1808
|
-
const segments = prefix.split("/");
|
|
1809
|
-
if (prefix.startsWith("/") || /[\\]/.test(prefix) || segments.some((segment) => segment === "..")) {
|
|
1810
|
-
throw new StorageError(
|
|
1811
|
-
400,
|
|
1812
|
-
STORAGE_CODES.invalidPath,
|
|
1813
|
-
`\u975E\u6CD5\u524D\u7F00 "${prefix}"\uFF08\u7981\u6B62 / \u5F00\u5934\u3001\u53CD\u659C\u6760\u6216 .. \u7A7F\u8D8A\uFF09`
|
|
1814
|
-
);
|
|
1815
|
-
}
|
|
1816
|
-
}
|
|
1817
|
-
return prefix ?? "";
|
|
1818
|
-
};
|
|
1819
1810
|
function createS3StorageDriver(options) {
|
|
1820
1811
|
const region = options.region ?? DEFAULT_REGION;
|
|
1821
1812
|
const quotaBytes = options.quotaBytes ?? PROJECT_QUOTA_BYTES;
|
|
@@ -1976,7 +1967,7 @@ function createS3StorageDriver(options) {
|
|
|
1976
1967
|
if (!res.ok) await mapError(res, `\u6587\u4EF6 "${path}" \u4E0D\u5B58\u5728\u6216\u4E0D\u53EF\u5220\u9664`);
|
|
1977
1968
|
},
|
|
1978
1969
|
async list(projectId, prefix) {
|
|
1979
|
-
const normalized =
|
|
1970
|
+
const normalized = assertStoragePrefix(prefix);
|
|
1980
1971
|
const keys = await listAllKeys(`${projectId}/${normalized}`);
|
|
1981
1972
|
const metas = await mapLimit(keys, HEAD_CONCURRENCY, async (entry) => {
|
|
1982
1973
|
const path = entry.key.slice(projectId.length + 1);
|
|
@@ -2237,6 +2228,17 @@ var SimSqlEngine = class {
|
|
|
2237
2228
|
}
|
|
2238
2229
|
return { changes: 0 };
|
|
2239
2230
|
}
|
|
2231
|
+
if (/^CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?/i.test(stmt)) {
|
|
2232
|
+
const idx = /^CREATE\s+(?:UNIQUE\s+)?INDEX\s+(?:IF\s+NOT\s+EXISTS\s+)?((?:"[^"]+")|([A-Za-z_][A-Za-z0-9_]*))\s+ON\s+((?:"[^"]+")|([A-Za-z_][A-Za-z0-9_]*))/i.exec(
|
|
2233
|
+
stmt
|
|
2234
|
+
);
|
|
2235
|
+
if (idx === null) throw new SimDbError("DB_UNSAFE_OP", `\u65E0\u6CD5\u89E3\u6790 CREATE INDEX \u8BED\u53E5`);
|
|
2236
|
+
const tableName = ident(idx[3]);
|
|
2237
|
+
if (this.tables[tableName] === void 0) {
|
|
2238
|
+
throw new SimDbError("DB_UNSAFE_OP", `CREATE INDEX \u76EE\u6807\u8868\u4E0D\u5B58\u5728\uFF1A${tableName}`);
|
|
2239
|
+
}
|
|
2240
|
+
return { changes: 0 };
|
|
2241
|
+
}
|
|
2240
2242
|
if (/^INSERT\s+INTO/i.test(stmt)) return this.execInsert(stmt, params);
|
|
2241
2243
|
if (/^UPDATE\s+/i.test(stmt)) return this.execUpdate(stmt, params);
|
|
2242
2244
|
if (/^DELETE\s+FROM/i.test(stmt)) return this.execDelete(stmt, params);
|
|
@@ -13,4 +13,5 @@ export interface S3StorageOptions {
|
|
|
13
13
|
/** BILL-005:项目级配额回调(billing 域注入)。 */
|
|
14
14
|
quotaCheck?: (projectId: string, projectedBytes: number) => Promise<void>;
|
|
15
15
|
}
|
|
16
|
+
/** 前缀合法性校验(list/usage 用):实现已上浮到 driver.ts 的 `assertStoragePrefix`(与 local 同一份)。 */
|
|
16
17
|
export declare function createS3StorageDriver(options: S3StorageOptions): StorageDriver;
|
package/dist/storage/driver.d.ts
CHANGED
|
@@ -64,3 +64,12 @@ export declare const STORAGE_CODES: {
|
|
|
64
64
|
* 合法路径为单层或多层相对段(如 `a`、`a/b.png`),每段不能是 `.`/`..`、空或含路径分隔符。
|
|
65
65
|
*/
|
|
66
66
|
export declare function assertSafeStoragePath(path: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* `list` / `usage` 的**前缀**校验:前缀不是完整路径,尾部空段(`a/` 表示目录 a 下全部)合法,
|
|
69
|
+
* 故不做 `assertSafeStoragePath` 的全段校验,只拦穿越风险(`/` 开头、反斜杠、`..` 段)。
|
|
70
|
+
*
|
|
71
|
+
* 去重背景:local / s3 / 浏览器 sim 三个驱动此前各写一份**逐字相同**的 12 行实现
|
|
72
|
+
* (s3 侧已抽成局部 `assertPrefix`,另两处没有复用)。这是路径穿越防线,任何一份被单独
|
|
73
|
+
* 放宽就是漏洞——必须只有一份。
|
|
74
|
+
*/
|
|
75
|
+
export declare function assertStoragePrefix(prefix: string | undefined): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adep/runtime",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@adep/types": "0.2.
|
|
28
|
+
"@adep/types": "0.2.3"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"test": "vitest run",
|