Benefits and Risks of Trusted Mode

When JavaScript code runs in trusted mode, you get these benefits, or risks, depending on your point of view and use case.

By placing a JavaScript library in trusted mode, admins and developers assume increased responsibility to secure code in their org. Make sure that you have examined the code and verified that it’s secure before allowing it to run in trusted mode.

JavaScript code in trusted mode can call any standard browser API directly, including APIs that are normally blocked or proxied by LWS. For example, cookies and local storage aren’t isolated in a sandbox. They’re exposed to any code that runs in trusted mode and uses the standard browser APIs.

Scripts in trusted mode can manipulate any part of the DOM, including Salesforce-managed elements and shadow DOM, without restrictions. For example, a trusted mode script could add script tags that potentially contain malicious code, or delete and replace the document’s body element with a spoof page.

Without the LWS layer, code in trusted mode can execute faster, especially in complex, resource-intensive applications.

Third-party libraries that rely on global state, such as jQuery and D3, work as intended but without LWS protection.

You can modify prototypes such as Array.prototype without restrictions, although this practice is still not recommended. If you modify a prototype, you can change the behavior of objects that inherit from it. The behavior changes can lead to bugs or security vulnerabilities in other parts of the app, including Salesforce code.

Scripts in trusted mode can bypass namespace encapsulation, which enables them to access or modify the private state and lifecycle events of other components.

See Also