dotlottie-web icon indicating copy to clipboard operation
dotlottie-web copied to clipboard

Unsafe-eval CSP issue

Open kevinvugts opened this issue 1 year ago • 6 comments

Overview

Dear,

I am concerned about the @lottiefiles/dotlottie-react library since it makes use of unsafe-eval. I have to enabled it to make the Lottie file work but I am doubting if this is the way to go.

Could you guys elaborate more on this security topic?

kevinvugts avatar Aug 23 '24 19:08 kevinvugts

@kevinvugts I couldn’t find any usage of eval within the dotlottie-* packages. Could you provide more details to help me investigate further?

I’ll also implement an ESLint rule to check for unsafe-eval in the CSP, which should help me identify the root cause.

theashraf avatar Aug 24 '24 02:08 theashraf

Based on this issue -> https://github.com/emscripten-core/emscripten/issues/20994, passing -sDYNAMIC_EXECUTION=0 when building the WASM bindings in the dotlottie-rs core player should fix this issue.

Update: This approach does not resolve the problem, as DYNAMIC_EXECUTION is already disabled in the core player (see https://github.com/LottieFiles/dotlottie-rs/blob/main/Makefile#L263) 🤔

theashraf avatar Aug 26 '24 03:08 theashraf

@kevinvugts One potential solution to consider is using wasm-unsafe-eval in your CSP header.

The wasm-unsafe-eval directive specifically controls WebAssembly execution and is more specific than unsafe-eval. If wasm-unsafe-eval is not specified in the script-src directive, WebAssembly will be blocked from loading and executing on the page. For more details, you can refer to this documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_webassembly_execution

theashraf avatar Aug 26 '24 07:08 theashraf

@kevinvugts One potential solution to consider is using wasm-unsafe-eval in your CSP header.

The wasm-unsafe-eval directive specifically controls WebAssembly execution and is more specific than unsafe-eval. If wasm-unsafe-eval is not specified in the script-src directive, WebAssembly will be blocked from loading and executing on the page. For more details, you can refer to this documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_webassembly_execution

Thank you so much for getting back to me. However, may I ask why the there are references to eval? This is a potential security hazard and shouldn't be present in a core library of LottieFiles in my opinion. CSP policies nowadays prevent these type of attacks by disabling them.

And I don't feel comfortable enabling these inline scripts to be able to be executed. What is your view on this?

kevinvugts avatar Aug 26 '24 11:08 kevinvugts

@kevinvugts, This issue arises from the generated code by the Emscripten library, which compiles our core dotLottie Rust player and handles the WebAssembly and JS-binding "glue" code.

It’s a common issue, as discussed here: https://github.com/WebAssembly/content-security-policy/issues/7. You might find success using wasm-unsafe-eval.

theashraf avatar Aug 27 '24 02:08 theashraf

wasm-unsafe-eval

Hi @theashraf

I think this would work for now. However, as the name suggests "wasm-unsafe-eval" it probably isn't a really secure option.

Isn't there another way to compile your core library? As this might open a lot of security risks to all users that use this native library of Lottie. :(

kevinvugts avatar Sep 02 '24 14:09 kevinvugts

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs.

github-actions[bot] avatar Nov 02 '24 02:11 github-actions[bot]

@kevinvugts Unfortunately, this is the only solution available for now. If you’re still experiencing the same issue after trying the suggested solution, please feel free to reopen it

theashraf avatar Jan 23 '25 08:01 theashraf