修复静态资源查找命中原型属性
白名单查找改为只认自有属性(Object.hasOwn),constructor、__proto__、toString 等名称按未知地址 404「地址不存在」, 不再落到 Object.prototype 上抛出类型错误。 经 HTTP 进入时路径恒以 / 开头,原代码对 /constructor 等本已返回 404;原型命中只在不带 / 的名称直接调用时出现, 因此本修复对现有 HTTP 响应无可见变化,测试同时覆盖 HTTP 与直接调用两种情形。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e68e08b524
commit
f9d217022c
2 files changed
+45
-1
No files matched your search
@@ -38,7 +38,8 @@ const ASSETS = {
|
||||
};
|
||||
// 白名单静态文件;其余(含任何 POST)一律 404。
|
||||
function serveStatic(res, route, isPost) {
|
||||
const file = ASSETS[route];
|
||||
// 只查自有属性,/constructor、/__proto__ 等不能命中原型。
|
||||
const file = Object.hasOwn(ASSETS, route) ? ASSETS[route] : undefined;
|
||||
if (!file || isPost) fail('地址不存在', 404);
|
||||
send(
|
||||
res,
|
||||
|
||||
Reference in new issue
Block a user