-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Inpage injection fails in Firefox under some CSP settings #3133
Comments
This issue now has a funding of 0.105 ETH (96.44 USD) attached to it.
|
I've added funding to this issue. I'd love for my site to work on FireFox with MetaMask without having to change my CSP. Thanks! |
I think I can fix this issue, but want to verify that my approach would be correct one. So the problem is that CSP won't allow inline script that is used here https://github.com/MetaMask/metamask-extension/blob/master/app/scripts/contentscript.js#L30. There's I've tried quickly and replacing |
Ok, this might be trickier than I expected. I see that loading with |
thank you for starting @evgeniuz! I can set up an example application that uses my current CSP if that would help. |
Sorry, but it seems that those two issues are inherently conflicting: when using I've noticed that you've tried to use hash to whitelist the script for inline, the file to hash is Removing Going to unassign myself from bounty, as I cannot find another solution at the moment. |
@evgeniuz thank you very much for all the help here. |
@marcusmolchany would you mind setting up a sample application? I'd like to play with setting up a workaround... |
Hey @dmihal here is a sample application. If you open it in chrome, you should see that web3 is injected into Here is the repo for the sample application. And this specifically is the CSP. |
@dmihal Would you like to give this one a go? Feel free to claim it on Gitcoin by clicking 'Start Work', if so! |
Is this still an issue? MetaMask seems to be working fine on FF for me. |
Hey @KennethAshley, this is only an issue if you have a Content Security Policy. Does MetaMask successfully inject web3 on my sample application when you use Firefox? |
This is a known bug in firefox. https://bugzilla.mozilla.org/show_bug.cgi?id=1267027. Comment on that issue to get it fixed soon. :) |
@dmxsf1 are you still working on this issue? |
1 similar comment
@dmxsf1 are you still working on this issue? |
@dmxsf1 are you still working on this issue? |
@amitkumar991 Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!
Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days |
Any update? Is this fixed in newer versions of Firefox or Metamask? |
Could this be fixed by Metamask or it should be reported to Firefox bugzilla? |
I believe the "correct" long term solution here is for dapps to change the way they interact with browser signers to better align with the official browser recommendation for pages and extensions communicating, which is via postMessage. I'm currently working on a solution to this, but it will be a big change that will require both dapp and extension buy-in and likely will be very slow to gain adoption. I wanted to drop a comment here just to make people aware of the potential futures, but at the moment I don't believe there is a great solution. If I am successful, my hope is to get this new mechanism implemented in MetaMask eventually (likely side-by-side with the existing injection technique) and then from there we will try to get dapps to adopt this technique over time. |
Does it mean extending the Web3 protocol? (if that's correct to call that a protocol) |
It means changing the way dapps communicate with "web3 enabled browsers". Rather than calling functions that were attached to |
Hey guys, seems this issue is very old problem, but probably there doesn't exist even hotfix for this issue yet ? So there is currently no way to use Metamask in Firefox ? (edit: with CSP enabled) Going to follow also this thread https://bugzilla.mozilla.org/show_bug.cgi?id=1267027 but it also seems to be there for 4 years, so we should probably not expect this to be fixed anytime soon. As I understand, to fix Metamask in FF, there would be need to change it's communication protocol to postMessages? Is that something what is planned? |
I use MetaMask on Firefox and it seems to work, though I think I'm on a pretty old version at the moment. What page are you unable to use? Is it served via HTTP or HTTPS? |
Both, I was testing on localhost:3000 (http) and also live site with https. Tested with nightly FF (v77) and stable v75. There is error regarding blocked And there is no Edit: Without enabled CSP it works. But we cannot turn that off and reduce web security. |
I created an NPM pacakge that "fixes" this.
import 'metamask-csp-firefox' Here is the source code (at least worked for me hehe): https://github.com/glitch-txs/metamask-csp-firefox Considerations: |
@glitch-txs check out https://github.com/MetaMask/detect-provider which is doing something similar to your lib. There's an existing bug with Firefox where it shouldn't enforce csp for injected content scripts that still hasn't been resolved: |
Thanks for clarifying! So sad it's 8 years old issue in Firefox :( |
I briefly looked into ways of solving this from MM's side. It's a bit tricky. Here are 2 ideas: 1. Xray visionFirefox Extensions are unique in that Firefox allows for extensions to add properties to the page's 2.
|
It would be nice to get a fix on this without altering too much the CSP as we want to keep the safe feature for the users. |
Yes! This is what I was surprised to find lacking when I encountered the issue. Otherwise, it's not safe, right? |
This issue has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 45 days if there is no further activity. The MetaMask team intends on reviewing this issue before close, and removing the stale label if it is still a bug. We welcome new comments on this issue. We do not intend on closing issues if they report bugs that are still reproducible. Thank you for your contributions. |
Still an issue. Thanks! |
Hi @gauthierpetetin this has been an issue since 2018, it's there any effort being made from Metamask team side to fix this in the near future?, or should we all just tell our clients to not use Metamask on Firefox when we have some csp on our app? Just to try and understand, a very straightforward answer will be very well received and really useful, thanks! |
Hi @FelipeCabreraB , we will reassess this issue in the next week and determine what our next steps are. We'll keep you informed. |
Hi @FelipeCabreraB , we've got a team discussion on this specific issue today. We're still not able to get an answer. As next step we'll try to reproduce it and assess how many dapps and users are impacted by it. We'll continue to keep you updated. |
Any update on this? Still seems to be an issue regarding wallets. |
Hi @coderbizman , this week, we've started working on a fix for this CSP issue in Firefox, consisting in overriding CSP headers. We'll share a PR in this thread as soon as available. |
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27770?quickstart=1) This PR implements a workaround for a long-standing Firefox MV2 bug where the content-security-policy header is not bypassed, triggering an error. The solution is simple: we check if the extension is MV2 running in Firefox. If yes, we override the header to prevent the error from raising. ## **Related issues** Fixes: #3133, MetaMask/MetaMask-planning#3342 ## **Manual testing steps** 1. Opening github.com should not trigger the CSP error ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <img width="726" alt="csp-toggle-off" src="https://github.com/user-attachments/assets/3877e37a-c205-4717-af6f-92e7f63a15a4"> <img width="1725" alt="reprod" src="https://github.com/user-attachments/assets/c923bedb-f73f-472c-8e0c-3545876a0bc3"> ### **After** <img width="719" alt="csp-toggle-on" src="https://github.com/user-attachments/assets/8e763391-1bac-4ff0-9d07-63436d7ee41d"> <img width="1723" alt="fixed" src="https://github.com/user-attachments/assets/1ca7c4e7-7c0e-4e75-8f0c-586ce99e4000"> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: David Murdoch <[email protected]>
The fix is planned to be released in version 12.8.0. |
Are there any downsides to overrriding this? |
We believe there are no downsides, but we can't be certain. Therefore, we've added a toggle in the settings to disable CSP headers overriding if needed. |
Hey, as far as I can tell, my content security policy is preventing MetaMask from injecting its scripts. This is only happening in Firefox. It works correctly in Chrome, Safari, Opera, and Brave. My
script-src
directive looks like this:and I'm seeing this csp violation in the js console:
Unfortunately Firefox only shows a preview of the blocked script. I've tried sha256 hashing each of the scripts in the latest Metamask release and adding them to the CSP, but that did not work. If you have any ideas that would be great!
Browser: Firefox 58.0.1
Operating System: Mac OSX 10.13.2
The text was updated successfully, but these errors were encountered: