dsh-design-studio 1.4.0 → 1.4.1

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.
Files changed (2) hide show
  1. package/lib/index.js +17 -1
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -90,6 +90,14 @@ export const inject = ['webServer']
90
90
  const API = '/dsh-design-studio/api/'
91
91
  const LOOPBACK = new Set(['127.0.0.1', '::1', '::ffff:127.0.0.1'])
92
92
  const LOOPBACK_HOST = /^(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/i
93
+ /**
94
+ * DSH 的 WebServer 准入(0.2.2 起,默认 auth: 'required')把验过登录与来源的 Peer 作为 handler 最后一个参数传进来。
95
+ * 拿到它说明这一条请求 DSH 已经放过了,不用再按「只认本机」挡一次——否则从局域网地址、反向代理、域名进来的
96
+ * 请求会被这一层挡掉(DSH 0.2.3 起 connection 的 requestRejection 也删了,老写法没有别的放行途径)。
97
+ * 只认主人(peer.principal.kind === 'owner',DSH 自己的共享接口也这么判):别的身份直接 403。
98
+ * 老版本 DSH 没有这个参数:req 上不会有这个标记,退回原来的 connection / loopback 判断。
99
+ */
100
+ const ADMITTED = Symbol('dsh-design-studio:admitted-peer')
93
101
  const MAX_BODY = 64 * 1024
94
102
  const MAX_EXPORT = 48 * 1024 * 1024 // 导出图片的请求体(base64)
95
103
  const MAX_DOC = 160 * 1024 * 1024 // 导出 PDF / PPT 的请求体(几十屏的 JPEG,base64)
@@ -1268,6 +1276,13 @@ export function apply(ctx) {
1268
1276
  // ── 接口 ──────────────────────────────────────────────────────────────────
1269
1277
 
1270
1278
  function admit(req, res) {
1279
+ const peer = req[ADMITTED]
1280
+ if (peer) {
1281
+ // DSH 的 WebServer 准入已经验过登录与来源(见 ADMITTED 的说明);设计台只给「主人」用:别的身份(以后 DSH 加的访客之类)一律不让进
1282
+ if (peer.principal && peer.principal.kind === 'owner') return true
1283
+ json(res, 403, { error: 'forbidden' })
1284
+ return false
1285
+ }
1271
1286
  const conn = connectionOf(ctx)
1272
1287
  if (conn) {
1273
1288
  const rejected = conn.requestRejection(req)
@@ -2499,7 +2514,8 @@ export function apply(ctx) {
2499
2514
  ctx.effect(() => ctx.webServer.register({
2500
2515
  kind: 'exact',
2501
2516
  path: API + key,
2502
- handler: (req, res) => {
2517
+ handler: (req, res, peer) => {
2518
+ if (peer) req[ADMITTED] = peer // 新版 DSH 准入给的 Peer:admit() 认它,见 ADMITTED 的说明
2503
2519
  Promise.resolve(handler(req, res)).catch((e) => {
2504
2520
  log(e)
2505
2521
  if (!res.headersSent) json(res, 500, { error: 'internal' })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-design-studio",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1 test/*.mjs"