AdguardBrowserExtension icon indicating copy to clipboard operation
AdguardBrowserExtension copied to clipboard

Website CSP can block AdGuard scripts in Firefox

Open HanabishiRecca opened this issue 4 years ago • 20 comments

  • AdGuard version: 3.5.23
  • Browser and version: Firefox 83.0

Some websites using strict CSP rules can block AdGuard scripts injection. E.g. here at github.com AdGuard can't make it's own scripts to work. image So all JS-related filters doesn't work with the such websites.

I've tried to override this behavior with a rule like this: github.com^$csp=script-src 'unsafe-inline' 'unsafe-eval' * But it doesn't work for some reason.

This is Firefox-only issue. Seems like Chrome allows extensions to inject scripts regardless of CSP. For a practical example, try to use a such rule: github.com#%#alert('Hi') It works in Chrome, but not in Firefox.

HanabishiRecca avatar Dec 11 '20 20:12 HanabishiRecca

Hello!

It looks like there should be no CSP check for extension resources. Apparently, this is a bug in the Firefox browser.

Chinaski1 avatar Dec 14 '20 11:12 Chinaski1

I constantly see a red Content Security Policy warning in Firefox Console during the normal navigation on Github.com too.

firefox_console

I'm using Firefox 84.0.2 x64. With the same browser I can't make more than 5 edits to a comment because my changes are not correctly retained between an edit and another. Currently I'm waiting official Github confirmation about it.

I've already tried without success:

  1. to disable "Filter update interval" option in Adguard
  2. to include github.com in the Adguard whitelist

isaak654 avatar Jan 21 '21 17:01 isaak654

With the same browser I can't make more than 5 edits to a comment because my changes are not correctly retained between an edit and another.

I don't think this is related. CSP errors means exactly the opposite: Adguard scripts don't work at this website. So there is literally nothing to interfere with.

HanabishiRecca avatar Jan 21 '21 17:01 HanabishiRecca

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 02 '21 16:06 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 03 '21 03:08 stale[bot]

А я то думал, - почему scriptlet'ы на некоторых сайтах не работают, а тут вон оно что... Не работают scriptlet'ы на GitHub'е, Яндексе и других сайтах, где они ОЧЕНЬ нужны.

Система Фильтры Антитрекинг
AdGuard v3.6.13 Базовый AdGuard         Русский Стандарт
FireFox v78.13 ESR Счётчиков и аналитики         Отслеживания по URL +Блокировка WebRTC
Win7SP1 Виджетов социальных сетей         Раздражителей +Удаление параметров отслеживания

XX-J avatar Dec 05 '21 02:12 XX-J

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 02 '22 09:03 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Jun 26 '22 09:06 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 27 '22 08:08 github-actions[bot]

Workaround this bug in FireFox is put security.csp.enable = false in about:config.

Странно, но GreaseMonkey как-то обходит эту проблему, а AdGuard и TamperMonkey - нет. Почему и, самое главное, Как?

XX-J avatar Aug 27 '22 14:08 XX-J

Workaround this bug in FireFox is put security.csp.enable = false in about:config.

Довольно жестоко глобально отключать CSP, безопасность страдает.

Странно, но GreaseMonkey как-то обходит эту проблему

Точно? Тогда нужно покопаться в его исходнике просто.

HanabishiRecca avatar Aug 27 '22 15:08 HanabishiRecca

Точно? Тогда нужно покопаться в его исходнике просто.

Точно! Использую версию 4.11 на FireFox v78.13 ESR, только он в iframe'ах скрипты не запускает. А TamperMonkey работает в iframe'ах, но не работает при строгом CSP.

А в коде я настолько сильно не разбираюсь - надо более опытного кодера.

XX-J avatar Aug 27 '22 15:08 XX-J

На деле конечно AdGuard при желании может легко обойти ограничения, так как имеет возможность модифицировать заголовки http. И технически даже сейчас есть возможность использования правил с модификатором $removeheader. Правда нужный заголовок content-security-policy специально запрещено трогать.

HanabishiRecca avatar Aug 27 '22 15:08 HanabishiRecca

А ОбезьянаВмасле работает по такому принципу - удаляет из заголовка обрабатываемых страниц параметр content-security-policy?

XX-J avatar Aug 27 '22 16:08 XX-J

А ОбезьянаВмасле работает по такому принципу - удаляет из заголовка обрабатываемых страниц параметр content-security-policy?

Не знаю, про заголовки это чисто мои размышления над способом решения проблемы.

HanabishiRecca avatar Aug 27 '22 16:08 HanabishiRecca

Я считаю такой способ решения проблемы для AdGuard'a сопоставим с отключением CSP, т.к. скрипты/скриптлеты необходимы/работают на очень многих страницах. Хотя, в крайнем случае, я бы согласился на опцию автовырезания CSP из заголовков тех доменов/страниц, которые: 1. Открываются в FireFox'e; 2. Для них есть правила со скриптами/скриптлетами.

Но, если в МаслянойОбезьяне применён другой, более хитрый метод обхода, то, думаю, он был бы предпочтительнее...

XX-J avatar Aug 27 '22 16:08 XX-J

Не обязательно вырезать, AdGuard имеет возможность модифицировать заголовки.

HanabishiRecca avatar Aug 27 '22 16:08 HanabishiRecca

...на опцию автовырезания CSP из заголовков...

Тем самым модифицируя его (т.е. заголовок).

XX-J avatar Aug 27 '22 17:08 XX-J

@maximtop, there seems to be a way around this issue for most cases. https://github.com/uBlockOrigin/uBlock-issues/issues/235#issuecomment-1344313926

ghost avatar Jan 19 '23 08:01 ghost

@FireFlashie thank you

maximtop avatar Jan 19 '23 09:01 maximtop