Repository navigation
修改默认值,允许http+ip访问;增加gateway和web日志落盘 - #4500
Conversation
| # Keep authentication cookies Secure on HTTPS, including behind a TLS proxy. | ||
| # Set to false only for an isolated deployment accessed directly over HTTP. | ||
| NEXENT_AUTH_COOKIE_SECURE=true | ||
| NEXENT_AUTH_COOKIE_SECURE=false |
There was a problem hiding this comment.
❌ 认证 Cookie 的 Secure 默认值被反转,默认部署的会话令牌可经明文 HTTP 传输
本次变更把 NEXENT_AUTH_COOKIE_SECURE 的示例默认值从 true 改为 false。frontend/server.js 中 const authCookieSecure = process.env.NEXENT_AUTH_COOKIE_SECURE !== "false" 将该值写入 buildCookieOptions 的 secure 属性,用于 nexent_access_token / nexent_refresh_token 等认证会话 Cookie(refresh token 的 maxAge 为 access token 的 10 倍)。标准与生产 Compose 的 nexent-web 服务通过 env_file 引用 deploy/env/.env,因此所有按该模板初始化的默认部署(包括位于 TLS 反向代理之后的生产形态)都会以不带 Secure 标志的方式下发会话 Cookie,令牌可经明文 HTTP 传输,被网络上的中间人窃听后即可实施会话劫持。紧邻的注释仍写明“仅在直接经 HTTP 访问的隔离部署中才设为 false”,与新的默认值自相矛盾。PR 目标“允许 http+ip 访问”属于部署可达性诉求,应让有此需求的隔离部署自行覆盖该值,而不是把不安全默认值放进全局环境模板。
上下文代码:
# Keep authentication cookies Secure on HTTPS, including behind a TLS proxy.
# Set to false only for an isolated deployment accessed directly over HTTP.
NEXENT_AUTH_COOKIE_SECURE=false
修复方案:
NEXENT_AUTH_COOKIE_SECURE=true
恢复默认 true,保持“默认安全”基线;确实需要 HTTP+IP 直连的隔离环境,应在该部署自己的 .env 中显式写入 NEXENT_AUTH_COOKIE_SECURE=false(与模板注释描述的使用方式一致),而经 TLS 代理访问的部署保持 true。
参考资料:
- OWASP Session Management Cheat Sheet - Cookies' Secure Attribute
- MDN Web Docs - Set-Cookie 的 Secure 属性
🤖 generated by github-code-review
| if (maxFileBytes > 0 && bytesInFile + piece.length > maxFileBytes) { | ||
| rotate(now); | ||
| } | ||
| appendFileSync(logPath, piece); |
There was a problem hiding this comment.
installServerFileLogging 通过 monkey-patch 拦截 process.stdout/stderr 的 write 方法,writeFileCopy 对每一条控制台输出都同步执行 mkdirSync/statSync/appendFileSync。appendFileSync 每次调用都要完成 open(2)+write(2)+close(2) 三个系统调用,字符串 chunk 还要额外做一次 Buffer.from 编码拷贝。这使得整个 Next.js 生产服务器的日志写入热路径变为同步磁盘 I/O:在日志高峰(代理错误风暴、调试输出)或慢速存储(网络卷、高负载磁盘)场景下会持续阻塞事件循环,放大请求延迟,甚至把瞬时故障放大为整体停顿。对照来看,gateway 侧同类需求使用的是保持文件打开的 Python logging handler,Web 侧也应避免逐条打开/关闭日志文件。
上下文代码:
const chunkLimit = maxFileBytes > 0 ? maxFileBytes : data.length;
for (let offset = 0; offset < data.length; offset += chunkLimit) {
const piece = data.subarray(offset, offset + chunkLimit);
if (maxFileBytes > 0 && bytesInFile + piece.length > maxFileBytes) {
rotate(now);
}
appendFileSync(logPath, piece);
bytesInFile += piece.length;
}
修复方案:
import {
closeSync,
mkdirSync,
openSync,
readdirSync,
renameSync,
statSync,
unlinkSync,
writeSync,
} from "node:fs";
let logFd;
function appendPiece(piece) {
if (logFd === undefined) {
logFd = openSync(logPath, "a");
}
writeSync(logFd, piece);
bytesInFile += piece.length;
}
// rotate(): before renameSync(logPath, `${logPath}.1`) run closeSync(logFd); logFd = undefined;
// writeFileCopy catch path: closeSync(logFd); logFd = undefined;
保持同步写入的顺序与可靠性语义,但让日志文件描述符常驻(以追加模式打开一次,轮转与写入失败路径中先关闭再重开),把每条日志的 open/write/close 三次系统调用降为一次 write,消除热路径上最大的重复开销;如需彻底解耦事件循环,可进一步改为常驻的 fs.createWriteStream 异步流并处理背压。
参考资料:
🤖 generated by github-code-review
Uh oh!
There was an error while loading. Please reload this page.