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

Function ɵɵvalidateAttribute

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

Source from the content-addressed store, hash-verified

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