fg-dynamic-component 3.0.0 → 4.0.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/README.md +77 -12
- package/fesm2022/fg-dynamic-component.mjs +1109 -285
- package/fesm2022/fg-dynamic-component.mjs.map +1 -1
- package/package.json +5 -3
- package/types/fg-dynamic-component.d.ts +204 -16
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ Create an Angular standalone signals based dynamic components tree through a JSO
|
|
|
7
7
|
|
|
8
8
|
| Angular | fg-dynamic-component | NPM package |
|
|
9
9
|
| ------- | -------------------- | ----------------------------- |
|
|
10
|
+
| 22.2.3 | 4.0.0 | `fg-dynamic-component@^4.0.0` |
|
|
10
11
|
| 22.2.3 | 3.0.0 | `fg-dynamic-component@^3.0.0` |
|
|
11
12
|
| 22.1.6 | 2.0.0 | `fg-dynamic-component@^2.0.0` |
|
|
12
13
|
| 17.2.4 | 1.1.1 | `fg-dynamic-component@^1.1.1` |
|
|
@@ -136,7 +137,7 @@ registry.register("MyDynamicComponent1", MyDynamicComponent1);
|
|
|
136
137
|
|
|
137
138
|
@Component({
|
|
138
139
|
selector: "my-component",
|
|
139
|
-
template: `<fg-dynamic [configuration]="configuration()" [registry]="registry" />`,
|
|
140
|
+
template: `<fg-dynamic [configuration]="configuration()" [registry]="registry" [typePolicy]="{ requireScopedRegistry: true }" />`,
|
|
140
141
|
imports: [FGDynamicComponent],
|
|
141
142
|
standalone: true
|
|
142
143
|
})
|
|
@@ -148,7 +149,9 @@ class MyComponent {
|
|
|
148
149
|
|
|
149
150
|
A configuration can only resolve component names that were explicitly registered in
|
|
150
151
|
the registry it receives. Names such as `constructor`, `__proto__` or `toString` are
|
|
151
|
-
never resolved from the registry prototype chain.
|
|
152
|
+
never resolved from the registry prototype chain. For untrusted configurations,
|
|
153
|
+
`[typePolicy]="{ requireScopedRegistry: true }"` makes the component refuse to fall
|
|
154
|
+
back to the global registry.
|
|
152
155
|
|
|
153
156
|
### Inputs and Outputs
|
|
154
157
|
|
|
@@ -191,10 +194,15 @@ class MyDynamicComponent1 {
|
|
|
191
194
|
You can update your inputs passing expressions binding using a view model and they will trigger standard Angular's life-cycle hooks
|
|
192
195
|
(of course you should consider which change detection strategy you are using).
|
|
193
196
|
|
|
197
|
+
Both classic `@Output() EventEmitter` and signal outputs created with
|
|
198
|
+
`output()` are supported. Output handlers receive `$event`; handlers are also
|
|
199
|
+
invoked when an output emits `null`/`undefined` (for example an
|
|
200
|
+
`EventEmitter<void>`).
|
|
201
|
+
|
|
194
202
|
```ts
|
|
195
203
|
@Component({
|
|
196
204
|
selector: 'my-component',
|
|
197
|
-
template: `<fg-dynamic [configuration]="configuration()" [(viewModel)]="viewModel" />`,
|
|
205
|
+
template: `<fg-dynamic [configuration]="configuration()" [(viewModel)]="viewModel" [expressionPolicy]="{ allowedMethods: ['handleSomething'] }" />`,
|
|
198
206
|
imports: [FGDynamicComponent],
|
|
199
207
|
standalone: true
|
|
200
208
|
})
|
|
@@ -262,6 +270,12 @@ class MyComponent {
|
|
|
262
270
|
> and non-primitive values are ignored. `href` and `src` only accept `http`,
|
|
263
271
|
> `https`, `mailto`, `tel` and relative URLs, so `javascript:` URLs are blocked
|
|
264
272
|
> even when they come from an expression.
|
|
273
|
+
>
|
|
274
|
+
> Boolean attributes (`hidden`, `disabled`, `readonly`, `required`, `checked`,
|
|
275
|
+
> `selected`, `multiple`) follow HTML presence semantics: a truthy value adds
|
|
276
|
+
> the attribute, while `false`/`null`/`undefined` removes it (it is never
|
|
277
|
+
> written as `hidden="false"`). Attributes deleted from the configuration, or
|
|
278
|
+
> whose value becomes `null`, are removed from the element.
|
|
265
279
|
|
|
266
280
|
### Reactive Forms
|
|
267
281
|
|
|
@@ -309,6 +323,16 @@ class MyComponent {
|
|
|
309
323
|
> Control names are interpreted as dot/bracket paths into the view model. Paths that
|
|
310
324
|
> contain `__proto__`, `prototype` or `constructor` are rejected, so a configuration
|
|
311
325
|
> cannot pollute object prototypes or register such names in a `FormGroup`.
|
|
326
|
+
>
|
|
327
|
+
> Dotted names such as `data.firstName` are wired through nested `FormGroup`s, so
|
|
328
|
+
> `formGroup.get('data.firstName')` works and no `FormGroup` key contains a dot.
|
|
329
|
+
> By default the component never reuses pre-existing controls or nested groups:
|
|
330
|
+
> a bind to an existing control is ignored unless
|
|
331
|
+
> `[formControlPolicy]="{ allowExistingControls: true }"` is set. Controls created
|
|
332
|
+
> by this component are removed on destroy; reused controls are left intact.
|
|
333
|
+
> Use `[formControlPolicy]="{ allowedControlNames: ['data.firstName'] }"` to
|
|
334
|
+
> restrict which control names a configuration may bind. Changing the form group
|
|
335
|
+
> or the evaluated control name rebinds the control automatically.
|
|
312
336
|
|
|
313
337
|
## Security
|
|
314
338
|
|
|
@@ -320,28 +344,69 @@ other string-to-code primitive is used. The supported subset is:
|
|
|
320
344
|
|
|
321
345
|
- literals (`'text'`, `42`, `true`, `false`, `null`, `undefined`), arrays and objects;
|
|
322
346
|
- member access `$vm().name`, `$vm()['name']` and optional chaining `$vm().a?.b`;
|
|
323
|
-
- calls
|
|
324
|
-
|
|
347
|
+
- calls to native built-ins (`$vm().items.map(...)`, `.filter(...)`, `.join(...)`,
|
|
348
|
+
string methods such as `.slice(...)`/`.trim(...)`) and expression-bodied arrow
|
|
349
|
+
functions;
|
|
325
350
|
- unary, arithmetic, comparison, logical, nullish and ternary operators;
|
|
326
351
|
- array/object spread and arrow functions whose body returns an expression or
|
|
327
352
|
contains a `return` statement.
|
|
328
353
|
|
|
329
354
|
Anything else is ignored at runtime (a warning is printed only in development mode).
|
|
330
|
-
In particular globals (`window`, `fetch`, …),
|
|
331
|
-
|
|
332
|
-
`
|
|
333
|
-
|
|
355
|
+
In particular globals (`window`, `fetch`, …), DOM host objects (`$event`,
|
|
356
|
+
`$event.target`, `document`, `localStorage`, `location`, …), assignments, `new`,
|
|
357
|
+
`this`, template literals, regular-expression literals and access to `__proto__`,
|
|
358
|
+
`prototype`, `constructor`, `caller`, `callee`, `arguments`, `call`, `apply` or
|
|
359
|
+
`bind` are rejected. Expressions are also limited in size, token count, nesting
|
|
360
|
+
depth and evaluation steps.
|
|
334
361
|
|
|
335
362
|
A value that contains neither `$vm` nor `$event` is used as a plain literal.
|
|
336
363
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
364
|
+
#### Expression policy (read-only by default)
|
|
365
|
+
|
|
366
|
+
Expressions are a capability boundary, not ordinary sandboxed user code. Custom
|
|
367
|
+
methods reachable from the view model are rejected by default; allow only the
|
|
368
|
+
methods a configuration actually needs:
|
|
369
|
+
|
|
370
|
+
```ts
|
|
371
|
+
template: `<fg-dynamic [configuration]="configuration()" [expressionPolicy]="{ allowedMethods: ['save'] }" />`
|
|
372
|
+
// Or, only for configurations you fully trust:
|
|
373
|
+
template: `<fg-dynamic [configuration]="configuration()" [expressionPolicy]="{ allowCustomMethods: true }" />`
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
`$vm()` remains available and returns the view model. `$vm.set` and `$vm.update`
|
|
377
|
+
are not exposed by default; enable view-model mutation explicitly with
|
|
378
|
+
`[expressionPolicy]="{ allowViewModelMutation: true }"`.
|
|
379
|
+
|
|
380
|
+
> Treat configurations as untrusted data unless they come from your own code.
|
|
381
|
+
> For multi-tenant/plugin scenarios prefer a scoped registry,
|
|
382
|
+
> `expressionPolicy.allowedMethods`, `formControlPolicy.allowedControlNames`,
|
|
383
|
+
> `[typePolicy]="{ requireScopedRegistry: true }"` and
|
|
384
|
+
> `[attributePolicy]="{ strict: true }"`.
|
|
385
|
+
|
|
386
|
+
#### Component type policy
|
|
387
|
+
|
|
388
|
+
A direct `type` may be an Angular component class or a registry name. Promise and
|
|
389
|
+
function loaders execute host code and are rejected by default; opt in with
|
|
390
|
+
`[typePolicy]="{ allowFunctionTypes: true }"`. `requireScopedRegistry` prevents an
|
|
391
|
+
untrusted configuration from falling back to the global registry.
|
|
340
392
|
|
|
341
393
|
### Other hardening
|
|
342
394
|
|
|
343
395
|
- Attribute names/values are validated (see [Attributes](#attributes)) and URL
|
|
344
396
|
schemes are checked.
|
|
397
|
+
- `attributePolicy.strict` disables `id`, `class`, `for`, `href` and `src`
|
|
398
|
+
(`name` remains available because it also drives form wiring), which mitigates
|
|
399
|
+
DOM clobbering and UI-redress scenarios. Combine it with a Content Security
|
|
400
|
+
Policy for untrusted content.
|
|
401
|
+
- `pattern` validators are size-limited, reject nested/ambiguous quantifiers and
|
|
402
|
+
quantified alternations (e.g. `(a+)+`, `(\d+(?:\d+)?)+`, `(a|aa)+`), and clone
|
|
403
|
+
`RegExp` values without `g`/`y` so validation is not stateful. The ReDoS check is
|
|
404
|
+
a conservative heuristic, not a full regular-expression analyzer.
|
|
405
|
+
- Configuration trees are limited in depth, total node count and
|
|
406
|
+
`inputs`/`outputs`/`attributes` key count/length. Repeated references and cycles
|
|
407
|
+
are rejected before rendering.
|
|
408
|
+
- Native string builders (`repeat`, `padStart`, `padEnd`, `join`) are bounded to
|
|
409
|
+
avoid memory/CPU exhaustion.
|
|
345
410
|
- The component registry uses a `Map` and never resolves inherited properties
|
|
346
411
|
(`constructor`, `__proto__`, …). Prefer a scoped registry for untrusted
|
|
347
412
|
configurations.
|