An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Allow bounded AMap script and worker resources https://github.com/siyuan-note/siyuan/issues/20129
Daniele0e6a7641c1d
diff --git a/app/electron/mapHostPolicy.js b/app/electron/mapHostPolicy.jsindex 0b8f59d3e2..5613b90685 100644--- a/app/electron/mapHostPolicy.js+++ b/app/electron/mapHostPolicy.js@@ -149,7 +149,8 @@ const createMapContentSecurityPolicy = (origin, provider) => {styles += " " + assets + "maplibre-gl.css";workers = "blob:";} else if (provider === "amap") {- scripts += " https://webapi.amap.com";+ scripts += " https://webapi.amap.com https://restapi.amap.com";+ workers = "blob:";connect = "https://webapi.amap.com https://restapi.amap.com https://vdata.amap.com";images += " https://webapi.amap.com https://a.amap.com https://*.is.autonavi.com";} else if (provider === "tencent") {diff --git a/app/electron/mapHostPolicy.test.js b/app/electron/mapHostPolicy.test.jsindex 73cf978e2e..39ca65d773 100644--- a/app/electron/mapHostPolicy.test.js+++ b/app/electron/mapHostPolicy.test.js@@ -114,6 +114,27 @@ test("bootstrap CSP has sandbox isolation and only fixed local assets plus the sassert.throws(() => createMapContentSecurityPolicy("http://example.com/a", "openfreemap"));});+test("AMap permits only its named REST script and blob workers without expanding network access", () => {+ const csp = createMapContentSecurityPolicy(origin, "amap");+ const directives = Object.fromEntries(csp.split(";").filter(value => value.trim()).map(value => {+ const [name, ...sources] = value.trim().split(/\s+/);+ return [name, sources];+ }));+ assert.deepEqual(directives["script-src"], [origin + "/stage/build/map/host.js", "https://webapi.amap.com", "https://restapi.amap.com"]);+ assert.deepEqual(directives["worker-src"], ["blob:"]);+ assert.deepEqual(directives["connect-src"], ["https://webapi.amap.com", "https://restapi.amap.com", "https://vdata.amap.com"]);+ assert.deepEqual(directives["frame-src"], ["'none'"]);+ assert.deepEqual(directives.sandbox, ["allow-scripts"]);+ for (const value of ["https://unknown.example/a", "http://restapi.amap.com/a", origin + "/api/system/getConf", "file:///tmp/a"]) {+ assert.equal(getMapRequestPolicy(value, "GET", origin, "amap"), undefined);+ }+ for (const provider of ["tencent", "baidu"]) {+ const policy = createMapContentSecurityPolicy(origin, provider);+ assert.match(policy, /worker-src 'none'/);+ assert.ok(!policy.includes("restapi.amap.com"));+ }+});+test("native geometry converts CSS to DIP, crops inward, and denies off-window or malformed bounds", () => {const value = {visible: true, bounds: {x: 10.2, y: 20, width: 200, height: 100},logicalSize: {width: 400, height: 200}, crop: {x: 40, y: 30}};diff --git a/app/src/protyle/render/av/map/bootstrap.ts b/app/src/protyle/render/av/map/bootstrap.tsindex 77e096dd2f..0e629f3893 100644--- a/app/src/protyle/render/av/map/bootstrap.ts+++ b/app/src/protyle/render/av/map/bootstrap.ts@@ -15,7 +15,8 @@ export const getAVMapLockedPolicy = (provider: AVMapProvider): string => {workers = "blob:";break;case "amap":- scripts = "https://webapi.amap.com";+ scripts = "https://webapi.amap.com https://restapi.amap.com";+ workers = "blob:";connect = "https://webapi.amap.com https://restapi.amap.com https://vdata.amap.com";images += " https://webapi.amap.com https://a.amap.com https://*.is.autonavi.com";break;@@ -31,7 +32,7 @@ export const getAVMapLockedPolicy = (provider: AVMapProvider): string => {break;}return `default-src 'none'; script-src ${scripts}; connect-src ${connect}; img-src ${images}; ` +- `style-src 'unsafe-inline'; font-src 'none'; worker-src ${workers}; child-src ${workers}; ` ++ `style-src 'unsafe-inline'; font-src 'none'; worker-src ${workers}; child-src ${provider === "openfreemap" ? workers : "'none'"}; ` +"frame-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'";};diff --git a/app/src/protyle/render/av/map/providersLoader.test.ts b/app/src/protyle/render/av/map/providersLoader.test.tsindex c3fdce0b55..798384a8f9 100644--- a/app/src/protyle/render/av/map/providersLoader.test.ts+++ b/app/src/protyle/render/av/map/providersLoader.test.ts@@ -262,4 +262,16 @@ describe("isolated provider loading", () => {dispose();}});+ it("allows only the approved AMap REST script and blob worker while keeping child frames disabled", () => {+ const policy = getAVMapLockedPolicy("amap");+ assert.match(policy, /(?:^|; )script-src https:\/\/webapi\.amap\.com https:\/\/restapi\.amap\.com;/);+ assert.match(policy, /worker-src blob:; child-src 'none'; frame-src 'none';/);+ assert.match(policy, /connect-src https:\/\/webapi\.amap\.com https:\/\/restapi\.amap\.com https:\/\/vdata\.amap\.com;/);+ assert.equal(/unsafe-eval|script-src[^;]*unsafe-inline|https:\/\/\*\.amap/.test(policy), false);+ for (const provider of ["tencent", "baidu"] as AVMapProvider[]) {+ assert.match(getAVMapLockedPolicy(provider), /worker-src 'none'; child-src 'none';/);+ assert.equal(getAVMapLockedPolicy(provider).includes("restapi.amap.com"), false);+ }+ assert.match(getAVMapLockedPolicy("openfreemap"), /worker-src blob:; child-src blob:;/);+ });});diff --git a/kernel/server/map_host.go b/kernel/server/map_host.goindex 3a1861e2d6..dac7a1ff77 100644--- a/kernel/server/map_host.go+++ b/kernel/server/map_host.go@@ -59,7 +59,8 @@ func mapHostPolicy(host, provider string) (string, bool) {styles += " " + local + "maplibre-gl.css"workers = "blob:"case "amap":- scripts += " https://webapi.amap.com"+ scripts += " https://webapi.amap.com https://restapi.amap.com"+ workers = "blob:"connect = "https://webapi.amap.com https://restapi.amap.com https://vdata.amap.com"images += " https://webapi.amap.com https://a.amap.com https://*.is.autonavi.com"case "tencent":diff --git a/kernel/server/map_host_test.go b/kernel/server/map_host_test.goindex 96f618ab4e..a8a21c6063 100644--- a/kernel/server/map_host_test.go+++ b/kernel/server/map_host_test.go@@ -52,6 +52,37 @@ func TestMapHostPolicy(t *testing.T) {}}+func TestMapHostAMapRestrictedWorkersAndScripts(t *testing.T) {+ policy, ok := mapHostPolicy("localhost:6806", "amap")+ if !ok {+ t.Fatal("AMap policy unavailable")+ }+ directives := map[string]string{}+ for _, part := range strings.Split(policy, ";") {+ fields := strings.Fields(part)+ if len(fields) > 0 {+ directives[fields[0]] = strings.Join(fields[1:], " ")+ }+ }+ for name, want := range map[string]string{+ "script-src": "localhost:6806/stage/build/map/host.js https://webapi.amap.com https://restapi.amap.com",+ "worker-src": "blob:",+ "connect-src": "https://webapi.amap.com https://restapi.amap.com https://vdata.amap.com",+ "frame-src": "'none'",+ "sandbox": "allow-scripts",+ } {+ if directives[name] != want {+ t.Fatalf("unexpected %s: %s", name, directives[name])+ }+ }+ for _, provider := range []string{"tencent", "baidu"} {+ other, _ := mapHostPolicy("localhost:6806", provider)+ if !strings.Contains(other, "worker-src 'none'") || strings.Contains(other, "restapi.amap.com") {+ t.Fatalf("AMap permissions leaked into %s", provider)+ }+ }+}+func TestMapHostStaticIsolationHeaders(t *testing.T) {old := util.WorkingDiroldBypass := util.SiYuanAccessAuthCodeBypass