@goodandready/dsh-cost-meter 0.8.10 → 0.8.12
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.
- package/lib/index.js +20 -5
- package/lib/updater.js +9 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -43,13 +43,18 @@ export function isTrustedCaller(request) {
|
|
|
43
43
|
const site = request.headers?.['sec-fetch-site']
|
|
44
44
|
if (site === 'cross-site') return false
|
|
45
45
|
|
|
46
|
-
const host = request.headers?.['
|
|
46
|
+
const host = request.headers?.['host']
|
|
47
47
|
const origin = request.headers?.['origin']
|
|
48
48
|
if (origin) {
|
|
49
49
|
try {
|
|
50
50
|
const url = new URL(origin)
|
|
51
|
-
if (
|
|
52
|
-
|
|
51
|
+
if (url.protocol === 'http:' || url.protocol === 'https:') {
|
|
52
|
+
if (host && url.host.toLowerCase() === host.toLowerCase()) return true
|
|
53
|
+
if (isLoopback(url.hostname) && isLoopback(remote)) return true
|
|
54
|
+
return false
|
|
55
|
+
}
|
|
56
|
+
// Non-http/https origin (e.g. dsh-app://app in DSH Desktop)
|
|
57
|
+
if (isLoopback(remote)) return true
|
|
53
58
|
return false
|
|
54
59
|
} catch {
|
|
55
60
|
return false
|
|
@@ -60,8 +65,13 @@ export function isTrustedCaller(request) {
|
|
|
60
65
|
if (referer) {
|
|
61
66
|
try {
|
|
62
67
|
const url = new URL(referer)
|
|
63
|
-
if (
|
|
64
|
-
|
|
68
|
+
if (url.protocol === 'http:' || url.protocol === 'https:') {
|
|
69
|
+
if (host && url.host.toLowerCase() === host.toLowerCase()) return true
|
|
70
|
+
if (isLoopback(url.hostname) && isLoopback(remote)) return true
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
// Non-http/https referer (e.g. dsh-app://app/ in DSH Desktop)
|
|
74
|
+
if (isLoopback(remote)) return true
|
|
65
75
|
return false
|
|
66
76
|
} catch {
|
|
67
77
|
return false
|
|
@@ -424,6 +434,11 @@ export function apply(ctx, config) {
|
|
|
424
434
|
path: STATE_PATH,
|
|
425
435
|
method: 'GET',
|
|
426
436
|
handler: async (req, res) => {
|
|
437
|
+
if (!isTrustedCaller(req)) {
|
|
438
|
+
res.writeHead(403, { 'Content-Type': 'application/json' })
|
|
439
|
+
res.end(JSON.stringify({ error: 'forbidden' }))
|
|
440
|
+
return
|
|
441
|
+
}
|
|
427
442
|
const cfg = current ?? config
|
|
428
443
|
|
|
429
444
|
// On the very first request after boot, wait for the fetch if we have
|
package/lib/updater.js
CHANGED
|
@@ -224,7 +224,15 @@ export function registerPluginUpdater(ctx, options) {
|
|
|
224
224
|
handler: async (request, response) => {
|
|
225
225
|
try {
|
|
226
226
|
const target = detectRuntime()
|
|
227
|
-
if (request.method === '
|
|
227
|
+
if (request.method === 'HEAD') {
|
|
228
|
+
response.writeHead(200, {
|
|
229
|
+
'content-type': 'application/json; charset=utf-8',
|
|
230
|
+
'cache-control': 'no-store',
|
|
231
|
+
})
|
|
232
|
+
response.end()
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
if (request.method === 'GET') {
|
|
228
236
|
const payload = await checkUpdateStatus(options, target)
|
|
229
237
|
writeResponseJson(response, 200, payload)
|
|
230
238
|
return
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-cost-meter",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.12",
|
|
4
4
|
"description": "DeepSeek Harness plugin: a session cost chip in the conversation header - live token usage by bucket, peak/off-peak tariff, and a countdown to the next tariff switch.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|