@ecomcx/create-ecomweb 1.26.0 → 1.28.0
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/validate.mjs +18 -0
- package/package.json +2 -2
package/lib/validate.mjs
CHANGED
|
@@ -35,6 +35,7 @@ export function validate(dir) {
|
|
|
35
35
|
}
|
|
36
36
|
if (!manifest.requires?.cms) warnings.push('Nên khai báo requires.cms, vd ">=1.0.0 <2.0.0"');
|
|
37
37
|
checkPermissions(manifest.permissions, errors, warnings);
|
|
38
|
+
checkCsp(manifest.csp, errors);
|
|
38
39
|
|
|
39
40
|
if (kind === "theme") {
|
|
40
41
|
const templates = path.join(dir, "templates");
|
|
@@ -149,6 +150,23 @@ function argsOf(ast, out = new Set()) {
|
|
|
149
150
|
|
|
150
151
|
/** locales/{ngôn-ngữ}.json: { "khoa": "thông điệp ICU" } — cú pháp ICU, khoá và biến khớp giữa các ngôn ngữ. */
|
|
151
152
|
/** Quyền trong manifest: viết sai → lỗi; quyền toàn phần mà chỉ cần vài domain / thư mục riêng → gợi ý quyền hẹp (CMS ≥ 1.8.0). */
|
|
153
|
+
const CSP_DIRECTIVES = ["script-src", "style-src", "img-src", "font-src", "connect-src", "frame-src", "media-src", "worker-src", "form-action"];
|
|
154
|
+
// Giữ khớp CspSources (Cms.Packaging): host https/wss cụ thể, được "*." đầu host, cổng, đường dẫn
|
|
155
|
+
const CSP_SOURCE = /^(https|wss):\/\/(\*\.)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*(:(\d{1,5}|\*))?(\/[A-Za-z0-9._~!$&()*+=:@%/-]*)?$/;
|
|
156
|
+
|
|
157
|
+
/** "csp": nguồn ngoài website cần nạp, vd { "font-src": ["https://fonts.gstatic.com"] } — CMS gộp vào CSP của website. */
|
|
158
|
+
function checkCsp(csp, errors) {
|
|
159
|
+
if (csp === undefined) return;
|
|
160
|
+
if (!csp || typeof csp !== "object" || Array.isArray(csp)) { errors.push('"csp" phải có dạng { "script-src": ["https://cdn.example.com"] }'); return; }
|
|
161
|
+
for (const [directive, list] of Object.entries(csp)) {
|
|
162
|
+
if (!CSP_DIRECTIVES.includes(directive)) { errors.push(`csp: chỉ thị "${directive}" không hỗ trợ (dùng: ${CSP_DIRECTIVES.join(", ")})`); continue; }
|
|
163
|
+
if (!Array.isArray(list)) { errors.push(`csp.${directive} phải là mảng nguồn`); continue; }
|
|
164
|
+
for (const src of list)
|
|
165
|
+
if (typeof src !== "string" || src.length > 300 || !CSP_SOURCE.test(src))
|
|
166
|
+
errors.push(`csp.${directive}: nguồn "${src}" không hợp lệ — chỉ nhận host https:// hoặc wss:// cụ thể, vd https://cdn.example.com (không "*", "https:", 'unsafe-…')`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
152
170
|
function checkPermissions(perms, errors, warnings) {
|
|
153
171
|
if (perms === undefined) return;
|
|
154
172
|
if (!Array.isArray(perms) || perms.some((p) => typeof p !== "string")) { errors.push('"permissions" phải là mảng chuỗi'); return; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecomcx/create-ecomweb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"description": "CLI tạo, kiểm tra, đóng gói và triển khai theme/plugin cho Ecomweb",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"README.md"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@ecomcx/ecomweb-admin-sdk": "1.
|
|
16
|
+
"@ecomcx/ecomweb-admin-sdk": "1.28.0",
|
|
17
17
|
"@ecomcx/ecomweb-content": "^1.14.0",
|
|
18
18
|
"adm-zip": "0.5.18",
|
|
19
19
|
"esbuild": "0.25.12",
|