公网临时链接改为不透明短 ID(/p/<22字符>),不再暴露文件名/会话名/签名
- public-files.js(新): 内存表 id → (会话, 相对路径, 过期时间);mint 顺手清过期项并兜底上限 - routes/public-files.js(新): GET /p/<id> 匿名取用(查表 → resolveInTask 复核 → sendDownload),未命中/过期一律 404 - routes/public-link.js: 不再签 HMAC,改为 mint 短 ID,返回 http://<IP>:8090/p/<id>(约 50 字符、纯 ASCII) 动因:原 URL 把文件名写了两遍再挂 64 位签名,共 300+ 字符;它会被模型抄进工具参数、并长期留在会话历史每轮重发 - download-send.js(新): 从 files.js 抽出 sendDownload/downloadDisposition,供浏览器下载与公网取用共用 - server.js: /p 挂在 auth.middleware 之前(匿名可达);浏览器下载那套签名链接保持不动 - docs: DEPLOY.md 4.1 / ARCHITECTURE.md(文件树、路由表、约束)/ README.md 同步
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
//
|
||||
// 用途:把任务目录里的文件变成一条短命的公网 URL,交给外部服务去取。第一个消费者是
|
||||
// MCP video_gen:智谱服务器生成视频前要自己来拉参考图,它不带 cookie、不带 Authorization,
|
||||
// 所以必须给它一条「不可猜 + 会过期」的链接 —— 这正是 files.js 一直在用的签名下载链接
|
||||
// (auth.js 的 isSignedDownload 已放行带 ?t= 的 /files/download* 请求)。
|
||||
// 这里解决的唯一问题:**沙箱里的 AI 怎么拿到一条签名**(签发接口要登录,executor 里没有凭据)。
|
||||
// 所以必须给它一条「不可猜 + 会过期」的链接。
|
||||
// 产出的形态是一个不透明短 ID(见 public-files.js 为什么不用签名 URL):
|
||||
// http://<IP>:8090/p/9fQ2mZ7xK4tR1vBn
|
||||
// 这解决的是:**沙箱里的 AI 怎么拿到一条公网链接**(签发接口要登录,executor 里没有凭据)。
|
||||
//
|
||||
// 为什么单独一个端口、且不映射到宿主机:
|
||||
// 这条接口没法用凭据保护(AI 的命令带不了凭据),那就干脆让外部**连都连不上**。
|
||||
@@ -12,8 +13,8 @@
|
||||
//
|
||||
// 边界(改这里务必保持):
|
||||
// 1. 只接受绝对路径,且必须落在 workspace_root 内;再反查会话表确认会话真实存在。
|
||||
// 2. 取 realpath 复核仍在任务根内:挡住"先 ln -s 一个外泄目标,再签它的链接"。
|
||||
// 3. 只签"已存在且是文件"的路径;签出来的链接由 files.js 的 serveDownload 再验一遍。
|
||||
// 2. 取 realpath 复核仍在任务根内:挡住“先 ln -s 一个外泄目标,再签它的链接”。
|
||||
// 3. 只签“已存在且是文件”的路径;取用侧(routes/public-files.js)会再复核一次目录边界。
|
||||
// 4. 返回 text/plain 而不是 JSON:AI 用 `curl -s` 拿到的 stdout 就是现成 URL,免解析。
|
||||
'use strict';
|
||||
|
||||
@@ -21,7 +22,7 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const express = require('express');
|
||||
const engine = require('../engine');
|
||||
const { signDownload } = require('../download-token');
|
||||
const publicFiles = require('../public-files');
|
||||
const log = require('../log');
|
||||
|
||||
const router = express.Router();
|
||||
@@ -62,14 +63,10 @@ router.get('/public-link', function (req, res) {
|
||||
return bad(res, 400, 'path 经符号链接指向了任务根之外,拒绝签发');
|
||||
}
|
||||
|
||||
const expires = Date.now() + pl.ttl_ms;
|
||||
const t = signDownload(sid, fileRel, expires);
|
||||
const url = pl.base_url + '/api/sessions/' + encodeURIComponent(sid)
|
||||
+ '/files/download-name/' + encodeURIComponent(path.basename(fileRel))
|
||||
+ '?path=' + encodeURIComponent(fileRel)
|
||||
+ '&expires=' + expires + '&t=' + t;
|
||||
const id = publicFiles.mint({ sessionId: sid, rel: fileRel, ttlMs: pl.ttl_ms });
|
||||
const url = pl.base_url + '/p/' + id;
|
||||
|
||||
log.info('public-link', sid + ' 签发公网链接(' + Math.round(pl.ttl_ms / 60000) + ' 分钟):' + fileRel);
|
||||
log.info('public-link', sid + ' 签发公网链接(' + Math.round(pl.ttl_ms / 60000) + ' 分钟):' + fileRel + ' → /p/' + id);
|
||||
res.type('text/plain').send(url + '\n');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user