Skip to content
This repository was archived by the owner on Jun 17, 2026. It is now read-only.
This repository was archived by the owner on Jun 17, 2026. It is now read-only.

Can the Subresource Integrity issue be solved by implementing it on the userscript itself? #1

Closed

Description

@qgustavor

Maybe just add a load function and load the libs in the main entrypoint:

async function loadLib (url, integrity) {
  eval(await fetch(url, { integrity }).then(r => r.text()))
}

await Promise.all([
  loadLib(
    'https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.2.7/purify.min.js',
    'sha256-QM/0krVDU6Vc35/7NpeGU5/7fVTSX5fdSh6JdbMJw10='
  ),
  loadLib(
    'https://cdn.jsdelivr.net/npm/markdown-it@14.1.0/dist/markdown-it.min.js',
    'sha256-OMcKHnypGrQOLZ5uYBKYUacX7Rx9Ssu91Bv5UDeRz2g='
  )
])

Some things to consider:

  1. Can we use eval on this context?
  2. Is it worth the additional security on Violentmonkey over the added complexity?
  3. Should we use indirect eval?
  4. Is there some risk on using eval which I'm missing out?

Activity

  1. qgustavor commented on Sep 27, 2025

    @qgustavor
    Author

    I guess this project is abandoned, no?

  2. hellodword commented on Sep 28, 2025

    @hellodword
    Owner

    I guess this project is abandoned, no?

    I’m still using it—I just forgot to watch it, so I didn’t get the issue-related emails. Sorry about that.

  3. qgustavor commented on Sep 28, 2025

    @qgustavor
    Author

    Oh, this is the first time I see the results of the "users no longer watch repositories automatically" change I was against affecting negatively a project. Glad to see you here!

  4. hellodword commented on Sep 28, 2025

    @hellodword
    Owner

    I have to admit that I know very little about writing userscripts and web security. As I mentioned in the README, the code itself was put together through vibe coding (with only my basic auditing). My concerns about dependency and rendering security mainly come from experience in other fields.

    With my current knowledge, I can’t give a solid answer on the implementation or security points you raised. I'll try to understand them and give them a try.

  5. hellodword commented on Sep 29, 2025

    @hellodword
    Owner
    // ==UserScript==
    // @name        New script github.com
    // @match       https://github.com/
    // @grant       GM.getValue
    // @run-at      document-start
    // ==/UserScript==
    
    eval('true')

    Failed in firefox:

    EvalError: call to eval() blocked by CSP
    Content-Security-Policy: The page’s settings blocked a JavaScript eval (script-src) from being executed because it violates the following directive: “script-src https://github.githubassets.com/” (Missing 'unsafe-eval')
    Source: true
    

    https://github.com/violentmonkey/violentmonkey/issues?q=is%3Aissue%20firefox%20CSP

    Any idea?

  6. qgustavor commented on Sep 29, 2025

    @qgustavor
    Author

    No, I don't have any. I guess this idea wouldn't work. But thanks for checking it anyway.

  7. hellodword commented on Sep 29, 2025

    @hellodword
    Owner

    How about using a bundler instead of @require

    https://www.npmjs.com/package/bundlemonkey

    Or implement a simple bundler that just removes the @require statements and inlines the source code directly into the final user.js, thereby avoiding the need to bring in additional toolchain dependencies for something so simple.

  8. qgustavor commented on Sep 29, 2025

    @qgustavor
    Author

    To be fair, I guess that's not hard to implement. At it simplest, run the code using esbuild, prepend the user-script, using GitHub Actions for CI and (maybe) GitHub Pages for deployment. Since you vibe coded this, here's an idea: https://claude.ai/public/artifacts/6ec04593-ebba-4fc4-a488-fa08e7470f54 (by the way, there are lots of issues with this generated code, but I guess you can work with that as a starting point)

  9. added a commit that references this issue on Sep 29, 2025
  10. hellodword commented on Sep 29, 2025

    @hellodword
    Owner

    I took a quick look at npm --verbose i foo, found the .tgz file and the .min.js files inside it, and wrote a very simple bundler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions