@snowcone-app/mockup-resolver 1.0.3 → 1.0.5
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/CHANGELOG.md +14 -0
- package/dist/index.js +1278 -282
- package/package.json +2 -2
- package/src/asset-allowlist.ts +14 -68
- package/src/index.ts +375 -169
- package/src/public-params.ts +9 -1
- package/src/resolve.ts +143 -1
- package/test/public-params.test.ts +11 -2
- package/test/resolve.test.ts +169 -0
- package/wrangler.jsonc +7 -2
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snowcone-app/mockup-resolver",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "URL signing and verification Cloudflare Worker",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "ISC",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@snowcone-app/mockup-url": "0.
|
|
9
|
+
"@snowcone-app/mockup-url": "0.3.1"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@cloudflare/workers-types": "^4.20250303.0",
|
package/src/asset-allowlist.ts
CHANGED
|
@@ -1,70 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* L2 asset-source allowlist (ADR-0076 security ladder)
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* L2 asset-source allowlist (ADR-0076 security ladder).
|
|
3
|
+
*
|
|
4
|
+
* The implementation moved to `@snowcone-app/mockup-url/asset-allowlist` so
|
|
5
|
+
* the backend publish/listing guard enforces the EXACT same origin-matching
|
|
6
|
+
* as this worker (QA finding 0013: a published design whose asset origin
|
|
7
|
+
* fails this check renders a blank catalog card; the guard refuses it at
|
|
8
|
+
* publish time instead). This module stays as the worker-local entry point —
|
|
9
|
+
* src/index.ts and the unit tests import from here.
|
|
5
10
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (char === "*") {
|
|
13
|
-
regexString += ".*?"; // Non-greedy match for any characters
|
|
14
|
-
} else if (/[.+\[\]?^${}()|\-\\]/.test(char)) {
|
|
15
|
-
// Corrected regex for special characters
|
|
16
|
-
regexString += "\\" + char; // Escape them
|
|
17
|
-
} else {
|
|
18
|
-
regexString += char;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
regexString += "$";
|
|
22
|
-
return new RegExp(regexString, "i"); // Added 'i' flag for case-insensitive matching
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Check a hostname against a glob allowlist (reuses globToRegExp). */
|
|
26
|
-
export function isHostAllowed(host: string, allowlist: string[]): boolean {
|
|
27
|
-
if (allowlist.length === 0) return true; // unset = any
|
|
28
|
-
for (const pattern of allowlist) {
|
|
29
|
-
if (pattern === "*") return true;
|
|
30
|
-
try {
|
|
31
|
-
if (globToRegExp(pattern).test(host)) return true;
|
|
32
|
-
} catch {
|
|
33
|
-
// skip malformed pattern
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type AssetAllowlistVerdict =
|
|
40
|
-
| { ok: true }
|
|
41
|
-
| { ok: false; status: 400 | 403; message: string };
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Run the L2 check over every developer-supplied image URL. No origin is ever
|
|
45
|
-
* exempt: catalog designs render by reference (`design=`, ADR-0086) with
|
|
46
|
-
* resolver-injected components, so they never pass through this check — the
|
|
47
|
-
* old EXEMPT_ASSET_ORIGINS escape hatch is gone.
|
|
48
|
-
*/
|
|
49
|
-
export function checkAssetUrls(
|
|
50
|
-
imageUrls: string[],
|
|
51
|
-
allowlist: string[] | undefined
|
|
52
|
-
): AssetAllowlistVerdict {
|
|
53
|
-
if (!allowlist || allowlist.length === 0) return { ok: true };
|
|
54
|
-
for (const imageUrl of imageUrls) {
|
|
55
|
-
let assetHost: string;
|
|
56
|
-
try {
|
|
57
|
-
assetHost = new URL(imageUrl).hostname;
|
|
58
|
-
} catch {
|
|
59
|
-
return { ok: false, status: 400, message: "Invalid asset URL" };
|
|
60
|
-
}
|
|
61
|
-
if (!isHostAllowed(assetHost, allowlist)) {
|
|
62
|
-
return {
|
|
63
|
-
ok: false,
|
|
64
|
-
status: 403,
|
|
65
|
-
message: "Asset source not allowed for this shop",
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return { ok: true };
|
|
70
|
-
}
|
|
11
|
+
export {
|
|
12
|
+
globToRegExp,
|
|
13
|
+
isHostAllowed,
|
|
14
|
+
checkAssetUrls,
|
|
15
|
+
type AssetAllowlistVerdict,
|
|
16
|
+
} from "@snowcone-app/mockup-url/asset-allowlist";
|