ryanmab / CensorDodge

Censor Dodge Web Proxy
Creative Commons Attribution Share Alike 4.0 International
63 stars 62 forks source link

Support of fonts woff2 + relative paths to fonts in CSS files #3

Closed abcnet-lu closed 3 years ago

abcnet-lu commented 3 years ago

Dear @ryanmab

First of all thank you for this proxy, it's really a piece of jewellery and finally a great replacement for glype which is not maintained for a couple of years now.

I've ran into a really tricky issue, and couldn't solve it.

Support of fonts woff2

Steps to reproduce:

  1. Proxy the page https://kikolani.com/

Outcome: The resource Inter-upright-var.woff2 is not found (404), not proxied and resolves locally instead of via proxy.

Additionally, error console: downloadable font: download failed (font-family: "Inter var" style:normal weight:100..900 stretch:100 src index:0): status=2147746065 source: [hidden]/assets/fonts/inter/Inter-upright-var.woff2

Caused by https://kikolani.com/wp-content/themes/twentytwenty/style.css?ver=1.0.1

@font-face {
    font-family: "Inter var";
    font-weight: 100 900; /* stylelint-disable-line font-weight-notation */
    font-style: normal;
    font-display: swap;
    src: url(./assets/fonts/inter/Inter-upright-var.woff2) format("woff2");
}

Support of fonts woff2 after patching

Steps to reproduce:

  1. Patch includes/class.censorDodge.php with "font/*" => array("ttf","otf","woff","woff2","eot"), to support woff2
  2. Proxy the page https://kikolani.com/

Outcome: The resource Inter-upright-var.woff2 is proxied and does not resolve locally anymore, but is not proxied properly.

Additionally, error console: downloadable font: rejected by sanitizer (font-family: "Inter var" style:normal weight:100..900 stretch:100 src index:0) source: [hidden]/?cdURL=aHR0cHM6Ly9raWtvbGFuaS5jb20vYXNzZXRzL2ZvbnRzL2ludGVyL0ludGVyLXVwcmlnaHQtdmFyLndvZmYy

Caused by improper proxification of

src: url(./assets/fonts/inter/Inter-upright-var.woff2) format("woff2");

Log:

[23:05:52 20-04-2021][xxx.xxx.xxx.xxx][404] https://kikolani.com/assets/fonts/inter/Inter-upright-var.woff2

It tries to resolve to https://kikolani.com/assets/fonts/inter/Inter-upright-var.woff2 instead of https://kikolani.com/wp-content/themes/twentytwenty/assets/fonts/inter/Inter-upright-var.woff2 (it appears that the proxification of a relative URL in the CSS is not made from the path where the CSS is hosted while it should).

Conclusion

If someone manages to fix this, kudos, because it sounds quite tricky and complicated. A real challenge.

Thank you and best regards.

Alexandre

ryanmab commented 3 years ago

Hi @abcnet-lu, Interesting! I'll take a closer look into this as soon as I can. Off the top of my head it looks as if Censor Dodge is not respecting "./" as a path relative to the style.css file, so is using the root domain assuming that's the correct location.

I'll let you know if I can get an update on this!

Thanks, Ryan

ryanmab commented 3 years ago

Hi @abcnet-lu, I just took a closer look, and believe I've found a solution which should solve the woff2 and relative path problems you found.

I'll be merging this into master soon, but if you wanted to check this out early and give it a test for yourself, you can here:

https://github.com/ryanmab/CensorDodge/tree/woff2-support

Thank you for your help so far!

Thanks, Ryan