@weibaohui/dsh-git-server 0.1.1 → 0.1.2

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/package.json +5 -4
  2. package/src/index.js +9 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weibaohui/dsh-git-server",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "dsh 插件 · Git 服务器:内嵌 ts-gogs(Gogs 的 TypeScript 平替),独立端口跑完整 Git 服务(HTTP clone/push、网页端、issue/PR/wiki),可复用 user-management 的用户名密码,设置页一键启停。",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,6 +24,10 @@
24
24
  "cordis.patch.yml",
25
25
  "README.md"
26
26
  ],
27
+ "engines": {
28
+ "node": ">=22.5",
29
+ "dsh": ">=0.1.2-rc.1"
30
+ },
27
31
  "dsh": {
28
32
  "bundle": {
29
33
  "patch": "./cordis.patch.yml"
@@ -57,9 +61,6 @@
57
61
  "ini": "^5.0.0",
58
62
  "marked": "^15.0.0"
59
63
  },
60
- "engines": {
61
- "node": ">=22.5"
62
- },
63
64
  "devDependencies": {
64
65
  "@types/better-sqlite3": "^7.6.12",
65
66
  "@types/busboy": "^1.5.4",
package/src/index.js CHANGED
@@ -25,7 +25,7 @@ const path = require('node:path')
25
25
  const engine = require('./runner')
26
26
 
27
27
  const name = engine.PLUGIN_ID
28
- const inject = ['webServer', 'settings']
28
+ const inject = ['webServer', 'settings', 'connection']
29
29
  const API_PREFIX = '/' + engine.PLUGIN_ID + '/api'
30
30
  const SETTINGS_NS = engine.PLUGIN_ID
31
31
 
@@ -452,6 +452,14 @@ module.exports = {
452
452
  kind: 'prefix',
453
453
  path: API_PREFIX,
454
454
  handler: async (req, res) => {
455
+ // 与其它 host 路由一致的信任栅栏:connection 服务的 Host/Origin 检查
456
+ // 加浏览器认证,防止本机任意网页跨站调用。
457
+ const rejection = ctx.connection.requestRejection(req)
458
+ if (rejection !== undefined) {
459
+ res.writeHead(rejection)
460
+ res.end()
461
+ return
462
+ }
455
463
  const url = new URL(req.url || '/', 'http://dsh.local')
456
464
  const rest = url.pathname.slice(API_PREFIX.length)
457
465
  try {