MCPcopy Create free account
hub / github.com/angular/angular / ɵɵvalidateAttribute

Function ɵɵvalidateAttribute

packages/core/src/sanitization/sanitization.ts:355–409  ·  view source on GitHub ↗
(value: T, tagName: string, attributeName: string)

Source from the content-addressed store, hash-verified

353 * @param attributeName The name of the attribute.
354 */
355export function ɵɵvalidateAttribute<T = any>(value: T, tagName: string, attributeName: string): T {
356 const index = getSelectedIndex();
357 const tNode: TNode | null = index === -1 ? null : getSelectedTNode();
358 if (tNode && tNode.type !== TNodeType.Element) {
359 return value;
360 }
361
362 const [namespace, resolvedTagName] = resolveElement(tagName);
363 const securityContext = checkSecurityContext(resolvedTagName, attributeName, namespace);
364
365 if (securityContext !== SecurityContext.ATTRIBUTE_NO_BINDING) {
366 return value;
367 }
368
369 const lView = getLView();
370 if (tNode) {
371 if (resolvedTagName === 'iframe') {
372 const element = getNativeByTNode(tNode, lView) as RElement;
373 enforceIframeSecurity(element as HTMLIFrameElement);
374 } else if (namespace === SVG_NAMESPACE || !namespace) {
375 const config =
376 SVG_ANIMATION_SENSITIVE_STATIC_VALUES[resolvedTagName]?.[attributeName.toLowerCase()];
377 if (config) {
378 const element = getNativeByTNode(tNode, lView) as SVGAnimateElement;
379 const attributeNameValue = getSecuritySensitiveSVGAnimationAttributeName(element, config);
380
381 if (attributeNameValue) {
382 const errorMessage =
383 ngDevMode &&
384 `Angular has detected that the \`${attributeName}\` was applied ` +
385 `as a binding to the <${resolvedTagName}> element${getTemplateLocationDetails(lView)}. ` +
386 `For security reasons, the \`${attributeName}\` can be set on the <${resolvedTagName}> element ` +
387 `as a static attribute only when the "attributeName" is set to \'${attributeNameValue}\'. \n` +
388 `To fix this, switch the \`${attributeNameValue}\` binding to a static attribute ` +
389 `in a template or in host bindings section.`;
390
391 throw new RuntimeError(RuntimeErrorCode.UNSAFE_ATTRIBUTE_BINDING, errorMessage);
392 }
393
394 return value;
395 }
396 }
397 }
398
399 const errorMessage =
400 ngDevMode &&
401 `Angular has detected that the \`${attributeName}\` was applied ` +
402 `as a binding to the <${resolvedTagName}> element${tNode ? getTemplateLocationDetails(lView) : ''}. ` +
403 `For security reasons, the \`${attributeName}\` can be set on the <${resolvedTagName}> element ` +
404 `as a static attribute only. \n` +
405 `To fix this, switch the \`${attributeName}\` binding to a static attribute ` +
406 `in a template or in host bindings section.`;
407
408 throw new RuntimeError(RuntimeErrorCode.UNSAFE_ATTRIBUTE_BINDING, errorMessage);
409}
410
411function getSecuritySensitiveSVGAnimationAttributeName(
412 element: SVGAnimateElement,

Callers

nothing calls this directly

Calls 9

getSelectedIndexFunction · 0.90
getSelectedTNodeFunction · 0.90
checkSecurityContextFunction · 0.90
getLViewFunction · 0.90
getNativeByTNodeFunction · 0.90
enforceIframeSecurityFunction · 0.90
resolveElementFunction · 0.85

Tested by

no test coverage detected