Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
A developer reviewing code security for LWC third-party JS integration within a Salesforce environment.
LWC

LWC Third-Party JS Security Review for AppExchange

Pulling third-party JavaScript libraries into Lightning Web Components for AppExchange takes careful handling, especially once you patch the code for Lightning Web Security (LWS) compliance. This guide covers static resource packaging, how to disclose your modifications, and what the security review looks at.

Key takeaways Provide the non-minified, patched source code of any third-party library you use, so the Security Review requirements are met. Use diff files or a detailed README to spell out the modifications made for LWS compliance. Pay close attention to how the editor handles user-supplied HTML, because it is a primary focus of both the code analyzer and the manual review of editor components. Locker Service is deprecated for new packages, so making the library LWS-compliant via patching is the correct technical path.

Integrating third-party JavaScript libraries in LWC for security review

When you develop a soql-in-loops-security-review-impact-for-managed-packages/" class="auto-link">managed package for AppExchange, pulling an external third-party JavaScript library into a Lightning Web Component (LWC) brings its own security considerations, particularly under the constraints of Lightning Web Security (LWS).

What follows covers the technical considerations and the disclosure steps required when you bundle patched third-party code as a static resource and load it dynamically via loadScript().

LWS compatibility and code patching

Lightning Web Security (LWS) restricts direct manipulation of global objects and the DOM access that was possible under the legacy Lightning Component Locker Service. Libraries that are not LWS-compliant on their own, which includes many older utility libraries, often need manual patching.

If you have modified the source code of a third-party library to ensure LWS compatibility, that modification must be documented for the Security Review team.

Technical strategy for integration:

  1. Bundling: use tools like esbuild to bundle the library, often outputting in an IIFE format suitable for direct loading.
  2. Static resource: bundle the output (minified or non-minified) as a Salesforce Static Resource.
  3. Loading: load the resource dynamically within your LWC using import { loadScript } from 'lightning/platformResourceLoader';.
import { LightningElement, api, wire } from 'lwc';
import { loadScript } from 'lightning/platformResourceLoader';
import TIP_TAP_LIB from '@salesforce/resourceUrl/tip_tap_min'; // Example resource name

export default class RichEditorComponent extends LightningElement {
    isLibLoaded = false;

    renderedCallback() {
        if (!this.isLibLoaded) {
            loadScript(this, TIP_TAP_LIB)
                .then(() => {
                    this.isLibLoaded = true;
                    // Initialize TipTap editor here
                })
                .catch(error => {
                    console.error('Error loading TipTap library:', error);
                });
        }
    }
}

Security review requirements for external code

The AppExchange Security Review process demands transparency about all executable code in your package, third-party dependencies included.

1. Minified vs. source code inclusion

Reviewers must be able to audit the security of all code executed in the Salesforce context.

  • Minified code: you use the minified version for runtime performance, but including only the minified version in your package for review is generally insufficient.
  • Source code disclosure: you must provide the non-minified, original source code of the library, including your necessary patches, for the security team to analyze effectively. This is typically uploaded alongside the package metadata or clearly linked.

2. Disclosing code modifications (patches)

If you modified the library source to achieve LWS compliance, the Security Review team needs a clear audit trail of those changes.

  1. A README: include a detailed README.md within the static resource source directory (or project root if packaging source) that explicitly lists the files modified, the reason for the modification (e.g., "Removed direct global object access to comply with LWS"), and the line numbers or sections changed.
  2. A diff file: a unified diff (.diff) comparing the original library version against your patched version is the clearest, most technical way to demonstrate exactly what you altered.

Both methods are preferable to simply stating modifications were made.

Security concerns with rich text editors

Rich text editor libraries (like Quill, TinyMCE, or TipTap) deal with user-supplied HTML input by design. That puts them under high scrutiny for cross-site scripting (XSS) vulnerabilities.

Common review triggers for editors:

  • Direct innerHTML usage: the use of .innerHTML or .outerHTML to inject content is flagged if the library handles raw, unsanitized input flowing directly from a user interaction point, even if it appears to be sanitizing input on the server side.
  • Sanitization: if your LWC wraps the editor, you must ensure that the final content rendered outside the editor component (e.g., displaying the stored HTML) uses appropriate sanitization (like the built-in Salesforce mechanisms or a trusted library) before being inserted into the DOM.

If the library performs internal DOM manipulation (which most editors do), the reviewer will assess whether the library's approach is safe under LWS, or if your patches adequately mitigate risks related to script injection via user input.

Best practices for packaging external JS in 2GP

For 2GP managed packages, static resources remain the standard mechanism for external JS dependencies not available via npm imports within the Salesforce structure (like libraries that must be loaded via loadScript).

Reviewer expectations:

  • Clear mapping: ensure your package.xml correctly references the static resource.
  • Dependency mapping: if the third-party library itself has dependencies, those must either be bundled into the primary static resource (e.g., using an IIFE bundle) or loaded as separate, clearly named static resources, documented in your README.
  • Locker/LWS context: state explicitly in your security documentation that the library was tested and verified against the LWS runtime environment, detailing any compatibility adjustments made.

Originally reported by reddit.com

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment