Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 778x 20x 20x 4x 18x 16x 16x 16x 13x 13x 13x 16x 16x 20x 20x 20x 20x 20x 3x 3x 19x 15x 15x 17x 17x 20x | /**
* @file htmlDirective.js
* @description What `data-ax-html` writes into an element, shared by the
* string renderer and the render-program runtime so the two cannot drift.
* @module lib/core/renderer/htmlDirective
*/
import { SafeHtml } from '../security/escapeHtml.js';
import { Sanitizer } from '../security/sanitize.js';
/**
* The default policy, which reports what it strips as AVX_W16 / AVX_W17, minus
* `id`, `name` and `target`. `id` and `name`: an injected element carrying either becomes a property of
* `window`, which would let a plain string clobber framework globals such as
* `window.__avenx_routers`. `target` goes too, so an injected link cannot open
* a new tab that keeps `window.opener` (reverse tabnabbing).
*/
const sanitizer = new Sanitizer({ disallowedAttributes: ['id', 'name', 'target'] });
/**
* Replaces an element's inner HTML from a `data-ax-html` value.
*
* A `SafeHtml` value is trusted and written as is. Any other value is run
* through the default `Sanitizer`, so allowed markup renders and anything
* dangerous is stripped with a warning. Never write a plain value unsanitized:
* that turns every `data-ax-html` in every application into an injection point.
*
* The sanitized result is cached on the element against its source, so a
* re-render with an unchanged value neither re-parses it, repeats the warnings,
* nor replaces the nodes it already wrote.
* @param {Element} element - The bound element.
* @param {any} value - The evaluated value.
*/
export function applyHtmlDirective(element, value) {
let markup;
if (value instanceof SafeHtml) {
markup = String(value);
} else if (value === null || value === undefined) {
markup = '';
} else {
const source = String(value);
if (element.__axHtmlSource !== source) {
element.__axHtmlMarkup = sanitizer.sanitize(source);
element.__axHtmlSource = source;
}
markup = element.__axHtmlMarkup;
}
// The browser re-serializes what it parsed (`<br />` reads back as `<br>`,
// `'` as `'`), so compare against what was read back after the last
// write, not the markup itself, or every re-render would rebuild the subtree.
if (element.__axHtmlWrote === markup && element.innerHTML === element.__axHtmlWritten) {
return;
}
if (element.innerHTML !== markup) {
element.innerHTML = markup;
}
element.__axHtmlWrote = markup;
element.__axHtmlWritten = element.innerHTML;
}
|