Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adhere to Content Security Policy? #37

Open
juj opened this issue Nov 24, 2021 · 3 comments
Open

Adhere to Content Security Policy? #37

juj opened this issue Nov 24, 2021 · 3 comments
Assignees

Comments

@juj
Copy link

juj commented Nov 24, 2021

Is it possible to use this compressor while adhering to CSP unsafe-eval policies? (i.e. avoid the use of eval(), new Function() etc.)

@lifthrasiir lifthrasiir added question Further information is requested and removed question Further information is requested labels Nov 25, 2021
@lifthrasiir
Copy link
Owner

That's an interesting question, because so far Roadroller was only used in the environment where CSP is intentionally disabled. If you can alter the CSP but want to avoid script-src "unsafe-eval", one possibility is to put hashes in the CSP:

<!doctype html>
<meta http-equiv="Content-Security-Policy" content="
    default-src 'self';
    script-src 'sha256-T1TBzCp/JoxyTN6FlxyZNO8iaImLgAhOKc82rZ9IhBs='
               'sha256-6nnaJ087RaGKbw89CHsxjtA6ddq/U+WmK8+9+TCGXyo='
">
<!-- the first hash for the the following <script>, the second hash for the embedded <script> -->
<script>alert('???');document.write(`<script>alert("hello?")<\/script>`);</script>

If you can't alter the CSP however, I think there is no solution (and there should be no solution since otherwise it would be an obvious loophole).

@lifthrasiir lifthrasiir self-assigned this Nov 25, 2021
@juj
Copy link
Author

juj commented Nov 25, 2021

Thanks - yeah, disabling CSP security selectively for the added script would work, if that is possible to deploy.

Are all roadroller optimization techniques fundamentally based on unsafe-eval? Or in other words, if there was a CSP-safe variant of roadroller, what kind of optimization techniques could remain there?

@lifthrasiir
Copy link
Owner

If you need to compress the JavaScript code, yes, it necessarily requires unsafe-eval because the decompressed code would have to be fed back to the JS engine. You may still be able to use Roadroller for compressing data files, which is possible but not yet well supported right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants