@egen-civitas/esm-embed-testing 0.1.0 → 0.2.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/CHANGELOG.md +13 -0
- package/bin/egen-embed-check.mjs +33 -0
- package/dist/check.d.ts +18 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +337 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +9 -4
- package/src/check.ts +81 -0
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @egen-civitas/esm-embed-testing
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 18cec62: Sécurité : `api.fetch` avec `path` est désormais **deny-by-default** (liste `paths` obligatoire dans le grant, normalisation anti-contournement : `..`, `%2e`, `//`…) pour qu'une app embarquée ne puisse pas appeler tout l'API du Core avec la session de l'utilisateur ; `negotiateCapabilities` ignore les entrées malformées ; tests de fuzz déterministes. Outillage : `egen-embed-check` (manifeste, capacités, `frame-ancestors`).
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [18cec62]
|
|
12
|
+
- @egen-civitas/esm-embed-protocol@0.2.0
|
|
13
|
+
- @egen-civitas/esm-embed-host@0.2.0
|
|
14
|
+
- @egen-civitas/esm-embed-client@0.1.1
|
|
15
|
+
|
|
3
16
|
## 0.1.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { checkEmbedApp, hasErrors } from '../dist/check.js';
|
|
4
|
+
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
const opt = (n) => {
|
|
7
|
+
const i = args.indexOf(n);
|
|
8
|
+
return i === -1 ? undefined : args[i + 1];
|
|
9
|
+
};
|
|
10
|
+
if (args.includes('--help') || !opt('--manifest')) {
|
|
11
|
+
console.log(`egen-embed-check — vérifie une app embarquée (manifeste, capacités, intégrabilité en iframe)
|
|
12
|
+
|
|
13
|
+
Usage : egen-embed-check --manifest egen-app.json [--shell https://egen.exemple.org] [--probe] [--allow-localhost]
|
|
14
|
+
|
|
15
|
+
--shell origine du Shell EGEN (contrôle CSP frame-ancestors)
|
|
16
|
+
--probe interroge l'URL de l'app (en-têtes X-Frame-Options / CSP)
|
|
17
|
+
--allow-localhost tolère http://localhost (développement)
|
|
18
|
+
|
|
19
|
+
Code de sortie : 1 si au moins une erreur.`);
|
|
20
|
+
process.exit(opt('--manifest') ? 0 : 1);
|
|
21
|
+
}
|
|
22
|
+
let manifest;
|
|
23
|
+
try {
|
|
24
|
+
manifest = JSON.parse(await readFile(opt('--manifest'), 'utf8'));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.error(`✗ manifeste illisible : ${e.message}`);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
const issues = await checkEmbedApp({ manifest, shellOrigin: opt('--shell'), probe: args.includes('--probe'), allowInsecureLocalhost: args.includes('--allow-localhost') });
|
|
30
|
+
const sym = { error: '✗', warn: '!', info: 'i' };
|
|
31
|
+
for (const i of issues) console.log(`${sym[i.level]} ${i.message}`);
|
|
32
|
+
if (!issues.length) console.log('✔ aucune remarque');
|
|
33
|
+
process.exit(hasErrors(issues) ? 1 : 0);
|
package/dist/check.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface CheckIssue {
|
|
2
|
+
level: 'error' | 'warn' | 'info';
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
export interface CheckOptions {
|
|
6
|
+
/** Manifeste `egen-app.json` déjà lu. */
|
|
7
|
+
manifest: unknown;
|
|
8
|
+
/** Origine du Shell EGEN (ex. `https://egen.exemple.org`) : active le contrôle d'intégration en iframe. */
|
|
9
|
+
shellOrigin?: string;
|
|
10
|
+
/** Interroge réellement l'URL de l'app (en-têtes `frame-ancestors`, `X-Frame-Options`). */
|
|
11
|
+
probe?: boolean;
|
|
12
|
+
allowInsecureLocalhost?: boolean;
|
|
13
|
+
fetchImpl?: typeof fetch;
|
|
14
|
+
}
|
|
15
|
+
/** Vérificateur d'app embarquée (`egen-embed-check`) : manifeste, hygiène des capacités demandées, intégrabilité en iframe. */
|
|
16
|
+
export declare function checkEmbedApp(o: CheckOptions): Promise<CheckIssue[]>;
|
|
17
|
+
export declare const hasErrors: (issues: CheckIssue[]) => boolean;
|
|
18
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,QAAQ,EAAE,OAAO,CAAC;IAClB,2GAA2G;IAC3G,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,+HAA+H;AAC/H,wBAAsB,aAAa,CAAC,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CA2D1E;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,UAAU,EAAE,YAA4C,CAAC"}
|
package/dist/check.js
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _ts_generator(thisArg, body) {
|
|
31
|
+
var f, y, t, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
40
|
+
return d(g, "next", {
|
|
41
|
+
value: verb(0)
|
|
42
|
+
}), d(g, "throw", {
|
|
43
|
+
value: verb(1)
|
|
44
|
+
}), d(g, "return", {
|
|
45
|
+
value: verb(2)
|
|
46
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
47
|
+
value: function() {
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
}), g;
|
|
51
|
+
function verb(n) {
|
|
52
|
+
return function(v) {
|
|
53
|
+
return step([
|
|
54
|
+
n,
|
|
55
|
+
v
|
|
56
|
+
]);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function step(op) {
|
|
60
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
62
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
63
|
+
if (y = 0, t) op = [
|
|
64
|
+
op[0] & 2,
|
|
65
|
+
t.value
|
|
66
|
+
];
|
|
67
|
+
switch(op[0]){
|
|
68
|
+
case 0:
|
|
69
|
+
case 1:
|
|
70
|
+
t = op;
|
|
71
|
+
break;
|
|
72
|
+
case 4:
|
|
73
|
+
_.label++;
|
|
74
|
+
return {
|
|
75
|
+
value: op[1],
|
|
76
|
+
done: false
|
|
77
|
+
};
|
|
78
|
+
case 5:
|
|
79
|
+
_.label++;
|
|
80
|
+
y = op[1];
|
|
81
|
+
op = [
|
|
82
|
+
0
|
|
83
|
+
];
|
|
84
|
+
continue;
|
|
85
|
+
case 7:
|
|
86
|
+
op = _.ops.pop();
|
|
87
|
+
_.trys.pop();
|
|
88
|
+
continue;
|
|
89
|
+
default:
|
|
90
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
91
|
+
_ = 0;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
95
|
+
_.label = op[1];
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
99
|
+
_.label = t[1];
|
|
100
|
+
t = op;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
if (t && _.label < t[2]) {
|
|
104
|
+
_.label = t[2];
|
|
105
|
+
_.ops.push(op);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (t[2]) _.ops.pop();
|
|
109
|
+
_.trys.pop();
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
op = body.call(thisArg, _);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
op = [
|
|
115
|
+
6,
|
|
116
|
+
e
|
|
117
|
+
];
|
|
118
|
+
y = 0;
|
|
119
|
+
} finally{
|
|
120
|
+
f = t = 0;
|
|
121
|
+
}
|
|
122
|
+
if (op[0] & 5) throw op[1];
|
|
123
|
+
return {
|
|
124
|
+
value: op[0] ? op[1] : void 0,
|
|
125
|
+
done: true
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
import { CAPABILITIES, FORBIDDEN_SESSION_FIELDS, patternCovers, validateManifest } from '@egen-civitas/esm-embed-protocol';
|
|
130
|
+
/** Vérificateur d'app embarquée (`egen-embed-check`) : manifeste, hygiène des capacités demandées, intégrabilité en iframe. */ export function checkEmbedApp(o) {
|
|
131
|
+
return _async_to_generator(function() {
|
|
132
|
+
var _caps_session, _caps_events, _caps_aitools, _caps_api, _caps_api1, issues, add, r, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _$e, m, caps, needApproval, fields, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, f, pub, own, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, p, tools, apiPaths, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _iterator3, _step3, p1, hosts, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, h, _o_fetchImpl, f1, _res_headers_get, _exec_, _exec, res, xfo, csp, fa, tokens, e;
|
|
133
|
+
return _ts_generator(this, function(_state) {
|
|
134
|
+
switch(_state.label){
|
|
135
|
+
case 0:
|
|
136
|
+
issues = [];
|
|
137
|
+
add = function add(level, message) {
|
|
138
|
+
return issues.push({
|
|
139
|
+
level: level,
|
|
140
|
+
message: message
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
r = validateManifest(o.manifest, {
|
|
144
|
+
allowInsecureLocalhost: o.allowInsecureLocalhost
|
|
145
|
+
});
|
|
146
|
+
if (!r.ok) {
|
|
147
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
148
|
+
try {
|
|
149
|
+
for(_iterator = r.errors[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
150
|
+
_$e = _step.value;
|
|
151
|
+
add('error', _$e);
|
|
152
|
+
}
|
|
153
|
+
} catch (err) {
|
|
154
|
+
_didIteratorError = true;
|
|
155
|
+
_iteratorError = err;
|
|
156
|
+
} finally{
|
|
157
|
+
try {
|
|
158
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
159
|
+
_iterator.return();
|
|
160
|
+
}
|
|
161
|
+
} finally{
|
|
162
|
+
if (_didIteratorError) {
|
|
163
|
+
throw _iteratorError;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return [
|
|
168
|
+
2,
|
|
169
|
+
issues
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
m = r.manifest;
|
|
173
|
+
caps = m.capabilities;
|
|
174
|
+
needApproval = Object.keys(caps).filter(function(id) {
|
|
175
|
+
return !CAPABILITIES[id].defaultGrant;
|
|
176
|
+
});
|
|
177
|
+
if (needApproval.length) add('info', "Capacit\xe9s \xe0 faire approuver par l'op\xe9rateur (grants) : ".concat(needApproval.join(', ')));
|
|
178
|
+
fields = (_caps_session = caps.session) === null || _caps_session === void 0 ? void 0 : _caps_session.fields;
|
|
179
|
+
if (Array.isArray(fields)) {
|
|
180
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
181
|
+
try {
|
|
182
|
+
for(_iterator1 = fields[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
183
|
+
f = _step1.value;
|
|
184
|
+
if (FORBIDDEN_SESSION_FIELDS.includes(String(f).split('.')[0])) add('error', "session.fields : \xab ".concat(f, " \xbb ne sera jamais transmis (identifiant de session ou jeton)"));
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
_didIteratorError1 = true;
|
|
188
|
+
_iteratorError1 = err;
|
|
189
|
+
} finally{
|
|
190
|
+
try {
|
|
191
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
192
|
+
_iterator1.return();
|
|
193
|
+
}
|
|
194
|
+
} finally{
|
|
195
|
+
if (_didIteratorError1) {
|
|
196
|
+
throw _iteratorError1;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
pub = (_caps_events = caps.events) === null || _caps_events === void 0 ? void 0 : _caps_events.publish;
|
|
202
|
+
if (Array.isArray(pub)) {
|
|
203
|
+
own = "app.".concat(m.route, ".*");
|
|
204
|
+
_iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = undefined;
|
|
205
|
+
try {
|
|
206
|
+
for(_iterator2 = pub[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true){
|
|
207
|
+
p = _step2.value;
|
|
208
|
+
if (p === '*' || /^\*/.test(String(p))) add('error', "events.publish : le motif \xab ".concat(p, " \xbb n'est pas support\xe9 (nommer le pr\xe9fixe, ex. ").concat(own, ")"));
|
|
209
|
+
else if (!patternCovers(own, String(p).replace(/\.\*$/, '.x'))) add('warn', "events.publish : \xab ".concat(p, " \xbb sort de l'espace conseill\xe9 ").concat(own));
|
|
210
|
+
}
|
|
211
|
+
} catch (err) {
|
|
212
|
+
_didIteratorError2 = true;
|
|
213
|
+
_iteratorError2 = err;
|
|
214
|
+
} finally{
|
|
215
|
+
try {
|
|
216
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
217
|
+
_iterator2.return();
|
|
218
|
+
}
|
|
219
|
+
} finally{
|
|
220
|
+
if (_didIteratorError2) {
|
|
221
|
+
throw _iteratorError2;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
tools = (_caps_aitools = caps['ai-tools']) === null || _caps_aitools === void 0 ? void 0 : _caps_aitools.tools;
|
|
227
|
+
if (Array.isArray(tools) && tools.some(function(t) {
|
|
228
|
+
return !String(t).includes('.');
|
|
229
|
+
})) add('warn', 'ai-tools.tools : préférer des noms d’outils préfixés (ex. studio.apply) pour éviter les collisions');
|
|
230
|
+
if (caps.api && !(Array.isArray(caps.api.paths) && caps.api.paths.length) && !(Array.isArray(caps.api.hosts) && caps.api.hosts.length)) add('warn', 'api : ni paths ni hosts demandés : aucun appel ne sera possible (deny-by-default)');
|
|
231
|
+
apiPaths = (_caps_api = caps.api) === null || _caps_api === void 0 ? void 0 : _caps_api.paths;
|
|
232
|
+
if (Array.isArray(apiPaths)) {
|
|
233
|
+
_iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = undefined;
|
|
234
|
+
try {
|
|
235
|
+
for(_iterator3 = apiPaths[Symbol.iterator](); !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true){
|
|
236
|
+
p1 = _step3.value;
|
|
237
|
+
if (p1 === '/*' || p1 === '*') add('warn', "api.paths : \xab ".concat(p1, " \xbb ouvre toute l'API du Core avec la session de l'utilisateur ; nommer les chemins n\xe9cessaires"));
|
|
238
|
+
}
|
|
239
|
+
} catch (err) {
|
|
240
|
+
_didIteratorError3 = true;
|
|
241
|
+
_iteratorError3 = err;
|
|
242
|
+
} finally{
|
|
243
|
+
try {
|
|
244
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
245
|
+
_iterator3.return();
|
|
246
|
+
}
|
|
247
|
+
} finally{
|
|
248
|
+
if (_didIteratorError3) {
|
|
249
|
+
throw _iteratorError3;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
hosts = (_caps_api1 = caps.api) === null || _caps_api1 === void 0 ? void 0 : _caps_api1.hosts;
|
|
255
|
+
if (Array.isArray(hosts)) {
|
|
256
|
+
_iteratorNormalCompletion4 = true, _didIteratorError4 = false, _iteratorError4 = undefined;
|
|
257
|
+
try {
|
|
258
|
+
for(_iterator4 = hosts[Symbol.iterator](); !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true){
|
|
259
|
+
h = _step4.value;
|
|
260
|
+
if (!/^https:\/\//i.test(String(h))) add('error', "api.hosts : \xab ".concat(h, " \xbb doit \xeatre une origine https"));
|
|
261
|
+
}
|
|
262
|
+
} catch (err) {
|
|
263
|
+
_didIteratorError4 = true;
|
|
264
|
+
_iteratorError4 = err;
|
|
265
|
+
} finally{
|
|
266
|
+
try {
|
|
267
|
+
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
|
268
|
+
_iterator4.return();
|
|
269
|
+
}
|
|
270
|
+
} finally{
|
|
271
|
+
if (_didIteratorError4) {
|
|
272
|
+
throw _iteratorError4;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (m.technology === 'nextjs' && m.navigation.mode === 'none') add('info', 'Next.js avec navigation « none » : l’URL du Core ne reflétera pas la page courante (partage de lien, F5)');
|
|
278
|
+
if (!caps.lifecycle && !caps.navigation) add('info', 'Aucune capacité navigation/lifecycle demandée : l’app ne pourra ni redimensionner l’iframe ni signaler qu’elle est prête (valeurs par défaut accordées si utilisées)');
|
|
279
|
+
if (!o.probe) return [
|
|
280
|
+
3,
|
|
281
|
+
4
|
|
282
|
+
];
|
|
283
|
+
f1 = (_o_fetchImpl = o.fetchImpl) !== null && _o_fetchImpl !== void 0 ? _o_fetchImpl : fetch;
|
|
284
|
+
_state.label = 1;
|
|
285
|
+
case 1:
|
|
286
|
+
_state.trys.push([
|
|
287
|
+
1,
|
|
288
|
+
3,
|
|
289
|
+
,
|
|
290
|
+
4
|
|
291
|
+
]);
|
|
292
|
+
return [
|
|
293
|
+
4,
|
|
294
|
+
f1(m.url, {
|
|
295
|
+
redirect: 'manual',
|
|
296
|
+
signal: AbortSignal.timeout(10000)
|
|
297
|
+
})
|
|
298
|
+
];
|
|
299
|
+
case 2:
|
|
300
|
+
res = _state.sent();
|
|
301
|
+
if (res.status >= 400) add('warn', "L'URL de l'app r\xe9pond HTTP ".concat(res.status));
|
|
302
|
+
if (res.status >= 300 && res.status < 400) add('info', "L'URL de l'app redirige (HTTP ".concat(res.status, ") : v\xe9rifier que la cible reste dans la m\xeame origine"));
|
|
303
|
+
xfo = res.headers.get('x-frame-options');
|
|
304
|
+
csp = (_res_headers_get = res.headers.get('content-security-policy')) !== null && _res_headers_get !== void 0 ? _res_headers_get : '';
|
|
305
|
+
fa = (_exec = /frame-ancestors\s+([^;]*)/i.exec(csp)) === null || _exec === void 0 ? void 0 : (_exec_ = _exec[1]) === null || _exec_ === void 0 ? void 0 : _exec_.trim();
|
|
306
|
+
if (xfo && /deny|sameorigin/i.test(xfo) && !fa) add('error', "X-Frame-Options: ".concat(xfo, " interdit l'int\xe9gration en iframe par le Shell (utiliser CSP frame-ancestors)"));
|
|
307
|
+
else if (fa !== undefined) {
|
|
308
|
+
tokens = fa.split(/\s+/);
|
|
309
|
+
if (o.shellOrigin && !tokens.includes('*') && !tokens.includes(o.shellOrigin)) add('error', "CSP frame-ancestors (".concat(fa, ") n'autorise pas le Shell ").concat(o.shellOrigin));
|
|
310
|
+
if (tokens.includes('*')) add('warn', 'CSP frame-ancestors « * » : n’importe quel site peut intégrer l’app (clickjacking) ; nommer l’origine du Shell');
|
|
311
|
+
if (tokens.includes("'none'")) add('error', "CSP frame-ancestors 'none' : intégration impossible");
|
|
312
|
+
} else add('warn', 'Aucune restriction frame-ancestors : l’app peut être intégrée par n’importe quel site (clickjacking) ; limiter à l’origine du Shell');
|
|
313
|
+
return [
|
|
314
|
+
3,
|
|
315
|
+
4
|
|
316
|
+
];
|
|
317
|
+
case 3:
|
|
318
|
+
e = _state.sent();
|
|
319
|
+
add('warn', "URL de l'app injoignable (".concat(e.message, ")"));
|
|
320
|
+
return [
|
|
321
|
+
3,
|
|
322
|
+
4
|
|
323
|
+
];
|
|
324
|
+
case 4:
|
|
325
|
+
return [
|
|
326
|
+
2,
|
|
327
|
+
issues
|
|
328
|
+
];
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
})();
|
|
332
|
+
}
|
|
333
|
+
export var hasErrors = function hasErrors(issues) {
|
|
334
|
+
return issues.some(function(i) {
|
|
335
|
+
return i.level === 'error';
|
|
336
|
+
});
|
|
337
|
+
};
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egen-civitas/esm-embed-testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Développer et tester une app embarquée sans le Core : hôte de test en mémoire, suite de conformité du protocole v2, simulateur de Shell (egen-embed-sim).",
|
|
6
6
|
"type": "module",
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"./package.json": {
|
|
26
26
|
"default": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"./check": {
|
|
29
|
+
"types": "./dist/check.d.ts",
|
|
30
|
+
"default": "./dist/check.js"
|
|
27
31
|
}
|
|
28
32
|
},
|
|
29
33
|
"source": true,
|
|
@@ -72,11 +76,12 @@
|
|
|
72
76
|
"vitest": "^4.1.2"
|
|
73
77
|
},
|
|
74
78
|
"dependencies": {
|
|
75
|
-
"@egen-civitas/esm-embed-client": "^0.1.
|
|
76
|
-
"@egen-civitas/esm-embed-host": "^0.
|
|
77
|
-
"@egen-civitas/esm-embed-protocol": "^0.
|
|
79
|
+
"@egen-civitas/esm-embed-client": "^0.1.1",
|
|
80
|
+
"@egen-civitas/esm-embed-host": "^0.2.0",
|
|
81
|
+
"@egen-civitas/esm-embed-protocol": "^0.2.0"
|
|
78
82
|
},
|
|
79
83
|
"bin": {
|
|
84
|
+
"egen-embed-check": "bin/egen-embed-check.mjs",
|
|
80
85
|
"egen-embed-sim": "bin/egen-embed-sim.mjs"
|
|
81
86
|
}
|
|
82
87
|
}
|
package/src/check.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CAPABILITIES, FORBIDDEN_SESSION_FIELDS, patternCovers, validateManifest, type EmbedManifest } from '@egen-civitas/esm-embed-protocol';
|
|
2
|
+
|
|
3
|
+
export interface CheckIssue {
|
|
4
|
+
level: 'error' | 'warn' | 'info';
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface CheckOptions {
|
|
9
|
+
/** Manifeste `egen-app.json` déjà lu. */
|
|
10
|
+
manifest: unknown;
|
|
11
|
+
/** Origine du Shell EGEN (ex. `https://egen.exemple.org`) : active le contrôle d'intégration en iframe. */
|
|
12
|
+
shellOrigin?: string;
|
|
13
|
+
/** Interroge réellement l'URL de l'app (en-têtes `frame-ancestors`, `X-Frame-Options`). */
|
|
14
|
+
probe?: boolean;
|
|
15
|
+
allowInsecureLocalhost?: boolean;
|
|
16
|
+
fetchImpl?: typeof fetch;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Vérificateur d'app embarquée (`egen-embed-check`) : manifeste, hygiène des capacités demandées, intégrabilité en iframe. */
|
|
20
|
+
export async function checkEmbedApp(o: CheckOptions): Promise<CheckIssue[]> {
|
|
21
|
+
const issues: CheckIssue[] = [];
|
|
22
|
+
const add = (level: CheckIssue['level'], message: string) => issues.push({ level, message });
|
|
23
|
+
|
|
24
|
+
const r = validateManifest(o.manifest, { allowInsecureLocalhost: o.allowInsecureLocalhost });
|
|
25
|
+
if (!r.ok) {
|
|
26
|
+
for (const e of r.errors) add('error', e);
|
|
27
|
+
return issues;
|
|
28
|
+
}
|
|
29
|
+
const m: EmbedManifest = r.manifest;
|
|
30
|
+
const caps = m.capabilities as Record<string, Record<string, unknown>>;
|
|
31
|
+
|
|
32
|
+
const needApproval = Object.keys(caps).filter((id) => !CAPABILITIES[id as keyof typeof CAPABILITIES].defaultGrant);
|
|
33
|
+
if (needApproval.length) add('info', `Capacités à faire approuver par l'opérateur (grants) : ${needApproval.join(', ')}`);
|
|
34
|
+
|
|
35
|
+
const fields = caps.session?.fields;
|
|
36
|
+
if (Array.isArray(fields)) for (const f of fields) if (FORBIDDEN_SESSION_FIELDS.includes(String(f).split('.')[0])) add('error', `session.fields : « ${f} » ne sera jamais transmis (identifiant de session ou jeton)`);
|
|
37
|
+
|
|
38
|
+
const pub = caps.events?.publish;
|
|
39
|
+
if (Array.isArray(pub)) {
|
|
40
|
+
const own = `app.${m.route}.*`;
|
|
41
|
+
for (const p of pub) {
|
|
42
|
+
if (p === '*' || /^\*/.test(String(p))) add('error', `events.publish : le motif « ${p} » n'est pas supporté (nommer le préfixe, ex. ${own})`);
|
|
43
|
+
else if (!patternCovers(own, String(p).replace(/\.\*$/, '.x'))) add('warn', `events.publish : « ${p} » sort de l'espace conseillé ${own}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const tools = caps['ai-tools']?.tools;
|
|
47
|
+
if (Array.isArray(tools) && tools.some((t) => !String(t).includes('.'))) add('warn', 'ai-tools.tools : préférer des noms d’outils préfixés (ex. studio.apply) pour éviter les collisions');
|
|
48
|
+
|
|
49
|
+
if (caps.api && !(Array.isArray(caps.api.paths) && caps.api.paths.length) && !(Array.isArray(caps.api.hosts) && caps.api.hosts.length)) add('warn', 'api : ni paths ni hosts demandés : aucun appel ne sera possible (deny-by-default)');
|
|
50
|
+
const apiPaths = caps.api?.paths;
|
|
51
|
+
if (Array.isArray(apiPaths)) for (const p of apiPaths) if (p === '/*' || p === '*') add('warn', `api.paths : « ${p} » ouvre toute l'API du Core avec la session de l'utilisateur ; nommer les chemins nécessaires`);
|
|
52
|
+
const hosts = caps.api?.hosts;
|
|
53
|
+
if (Array.isArray(hosts)) for (const h of hosts) if (!/^https:\/\//i.test(String(h))) add('error', `api.hosts : « ${h} » doit être une origine https`);
|
|
54
|
+
|
|
55
|
+
if (m.technology === 'nextjs' && m.navigation.mode === 'none') add('info', 'Next.js avec navigation « none » : l’URL du Core ne reflétera pas la page courante (partage de lien, F5)');
|
|
56
|
+
if (!caps.lifecycle && !caps.navigation) add('info', 'Aucune capacité navigation/lifecycle demandée : l’app ne pourra ni redimensionner l’iframe ni signaler qu’elle est prête (valeurs par défaut accordées si utilisées)');
|
|
57
|
+
|
|
58
|
+
if (o.probe) {
|
|
59
|
+
const f = o.fetchImpl ?? fetch;
|
|
60
|
+
try {
|
|
61
|
+
const res = await f(m.url, { redirect: 'manual', signal: AbortSignal.timeout(10_000) });
|
|
62
|
+
if (res.status >= 400) add('warn', `L'URL de l'app répond HTTP ${res.status}`);
|
|
63
|
+
if (res.status >= 300 && res.status < 400) add('info', `L'URL de l'app redirige (HTTP ${res.status}) : vérifier que la cible reste dans la même origine`);
|
|
64
|
+
const xfo = res.headers.get('x-frame-options');
|
|
65
|
+
const csp = res.headers.get('content-security-policy') ?? '';
|
|
66
|
+
const fa = /frame-ancestors\s+([^;]*)/i.exec(csp)?.[1]?.trim();
|
|
67
|
+
if (xfo && /deny|sameorigin/i.test(xfo) && !fa) add('error', `X-Frame-Options: ${xfo} interdit l'intégration en iframe par le Shell (utiliser CSP frame-ancestors)`);
|
|
68
|
+
else if (fa !== undefined) {
|
|
69
|
+
const tokens = fa.split(/\s+/);
|
|
70
|
+
if (o.shellOrigin && !tokens.includes('*') && !tokens.includes(o.shellOrigin)) add('error', `CSP frame-ancestors (${fa}) n'autorise pas le Shell ${o.shellOrigin}`);
|
|
71
|
+
if (tokens.includes('*')) add('warn', 'CSP frame-ancestors « * » : n’importe quel site peut intégrer l’app (clickjacking) ; nommer l’origine du Shell');
|
|
72
|
+
if (tokens.includes("'none'")) add('error', "CSP frame-ancestors 'none' : intégration impossible");
|
|
73
|
+
} else add('warn', 'Aucune restriction frame-ancestors : l’app peut être intégrée par n’importe quel site (clickjacking) ; limiter à l’origine du Shell');
|
|
74
|
+
} catch (e) {
|
|
75
|
+
add('warn', `URL de l'app injoignable (${(e as Error).message})`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return issues;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const hasErrors = (issues: CheckIssue[]) => issues.some((i) => i.level === 'error');
|
package/src/index.ts
CHANGED