Angular 2+ security: Is it safe to *read* values f

2019-06-11 04:13发布

问题:

From the Angular security guide there's this:

The built-in browser DOM APIs don't automatically protect you from security vulnerabilities. For example, document, the node available through ElementRef, and many third-party APIs contain unsafe methods. Avoid directly interacting with the DOM and instead use Angular templates where possible.

'interacting' is a bit vague. I've sort of assumed that reading values from the DOM is safe. And indeed, all the examples on the page are involving content being inserted into the DOM. But it doesn't explicitly say that reading values can be dangerous. My primary use of ElementRef has been to read values, as that is highly useful for certain things, like a solution I have in mind for this question, where I might be able to inspect parent elements to switch modes in a component:

stackoverflow.com/questions/50862334/how-to-know-if-component-is-populated-by-a-route-or-by-template-in-angular-2

In addition, Renderer2 provides functionality for inserting content, but has no features facilitating reading content.