Skip to content

Updated Recommendations for CSP and Avoiding 'unsafe-eval' #156

@rujep

Description

@rujep

Hello Dynamsoft Team,

We are a team developing an Angular web app with PWA capabilities and are integrating the dynamsoft-barcode-reader-bundle (version 10.4.3100). Our application hosts the required Dynamsoft resources locally to ensure quick and seamless caching via our service worker. These resources include the following:

/assets/dynamsoft-capture-vision-std/std.js
/assets/dynamsoft-capture-vision-std/std.wasm
/assets/dynamsoft-image-processing/dip.wasm
/assets/dynamsoft-core/core.js
/assets/dynamsoft-core/core.worker.js
/assets/dynamsoft-core/core.wasm
/assets/dynamsoft-license/license.js
/assets/dynamsoft-license/dls.license.dialog.html
/assets/dynamsoft-license/license.wasm
/assets/dynamsoft-utility/utility.js
/assets/dynamsoft-barcode-reader/dbr.js
/assets/dynamsoft-barcode-reader/dbr.wasm
/assets/dynamsoft-barcode-reader/DBR-PresetTemplates.json
/assets/dynamsoft-capture-vision-router/cvr.js
/assets/dynamsoft-capture-vision-router/cvr.wasm
/assets/dynamsoft-capture-vision-router/cvr.worker.js
/assets/dynamsoft-camera-enhancer/dce.js
/assets/dynamsoft-camera-enhancer/dce.ui.html

Currently, we are concerned about having to use 'unsafe-eval' in our Content Security Policy (CSP). Our CSP configuration is defined in a web.config file and looks like this:

<add name="Content-Security-Policy"
     value="default-src 'self' login.microsoftonline.com; 
            script-src 'self' 'unsafe-eval'; 
            style-src 'self' 'unsafe-inline'; 
            img-src http: https: data:; 
            connect-src 'self' login.microsoftonline.com mdls.dynamsoftonline.com sdls.dynamsoftonline.com data:; 
            frame-ancestors 'none'; 
            font-src 'self' data:" />

This setup works but requires 'unsafe-eval' for the library to function, which we would like to avoid for security reasons. Ideally, we aim to:

  • Use 'wasm-unsafe-eval' instead of 'unsafe-eval' (or a similarly scoped policy).
  • Specify more restrictive CSP rules (e.g., per-directory or per-file rules) for Dynamsoft resources to minimize the risk.

We came across Issue #102 from October 2021, which provides minimum CSP requirements. However, that post is over three years old, and we were wondering if there have been any updates since then.

Additionally, we attempted to set CSP-specific rules for Dynamsoft files by using <location> nodes in web.config:

<location path="<path-to-dynamsoft-files>">
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Content-Security-Policy" 
             value="...specific CSP rules here..." />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</location>

Unfortunately, this approach resulted in an error when trying to load core.worker.js.

Questions:

  1. Are there updated recommendations for configuring CSP to avoid 'unsafe-eval' with Dynamsoft libraries?
  2. Is there a roadmap or consideration for removing the reliance on 'unsafe-eval' in the library?
  3. Are there best practices for hosting Dynamsoft resources locally while maintaining a secure CSP?

Thank you for your guidance and support!

Best regards,
Rune

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions