Safari Support (new safari API)
The new safari API seems like it may support https-everywhere. https://developer.apple.com/library/prerelease/content/documentation/NetworkingInternetWeb/Conceptual/SafariAppExtension_PG/index.html#//apple_ref/doc/uid/TP40017319 is the documentation. It is currently for the new safari 10 in macOS Sierra. I believe it may allow for an extension to rewrite HTTP requests as HTTPS, but Im not completely sure.
May we can leave the political disusscion on twitter and reddit and focus us here more on the technical aspect?
I worked on this for a few hours last night and was able to make some progress. I put my work in a repo here: https://github.com/afarrow/HTTPS-Everywhere-Safari-Test
The readme should explain what I learned and provide a good starting point for anyone wanting to work more on this.
Thanks @afarrow ! 🙌
So it sounds like Safari support is blocked due to its inability to handle large JSON files? Is this a known issue or do you know of any workarounds? From this WWDC talk it sounds like it's possible to block dynamically via the Javascript API, too.
@jessesquires
Yes, right now it seems the limitation is on the size of the JSON files. I also don't know of any way to do more complex rewrites (ex: rewrite example.com to secure.example.com), set the secure cookie flag or have exclusions. But I think there's value in the extension even if we can't do any of those things. I think the most promising area to explore is probably building the extension with XCode where you can use Swift or JavaScript. I haven't explored any workarounds to the JSON size issue yet but I'm going to spend some time later this week working on it.
As far as I know, there is a hard limit of 50k rules per extension (json), not on the binary size of the json.
@javabean Yes, I ran into the 50k limit last night, thanks for confirming my suspicions. I don't know why the JSON files I was generating earlier were failing with a lot fewer rules than that. Perhaps an issue with the script I wrote. Do you know if that limit is per JSON file? For example, could you have 2 JSON files with 50k rules each to get around the limitation? Or is that 50k limit in place regardless of how many JSON files the rules are spread over?
Edit: Oh, and just an update on the XCode idea. I tried to paste a ~20k line JSON file into XCode and it crashed. So I'm back to using the Safari Extension Builder but I'm now experimenting with using the JavaScript API that extensions have access to: https://developer.apple.com/library/content/documentation/Tools/Conceptual/SafariExtensionGuide/Introduction/Introduction.html
I'm not sure a Safari Extension would enable us to make-https: extensions can manipulate the DOM, but since it is already loaded it is too late to change the load type.
An extension can use content-blocking rules, but we're back to square 1 where we hit the 50k limit.
As far as I know, 1 extension can have only 1 Safari Content Blocker (and hence 1 JSON file, and 50k rules max).
You can still opt to build more than 1 extension to cover the whole range of rules we have, even it it will be weird for the user (she will have to install 2+ applications / extensions)!
How many rules do we currently have in the https-everywhere database (the ones that can be expressed as Safari Content Blocker rules)?
I'm not sure a Safari Extension would enable us to make-https: extensions can manipulate the DOM, but since it is already loaded it is too late to change the load type.
The JavaScript API actually includes the class SafariBeforeNavigateEvent. This event fires "when the user navigates to a new page, before the page is loaded". So for example I experimented the other night with adding a Global HTML Page which is basically an HTML file that you use to add JavaScript to your extension. My global html file looks like this:
<!DOCTYPE html>
<html>
<script src="./test.js"></script>
</html>
Then in the test.js file I was able to add:
safari.application.addEventListener('beforeNavigate', handleEvent, true);
function handleEvent(event) {...}
and the handleEvent function fired before the page was ever loaded. And as Apple states on the API page, "you can use the preventDefault method to prevent the new page from loading".
So my two ideas that stemmed from this were either:
- Switching out the JSON files on the fly based on what site was requested (don't think this would work well if at all because Safari has to transform the JSON to bytecode)
- Manually rewriting the URL in the handleEvent function. So far I haven't found a way to do that though
How many rules do we currently have in the
https-everywheredatabase (the ones that can be expressed as Safari Content Blocker rules)?
A rough count is 82678 rules. I got this by running a script that ignored all files that had more than one rewrite rule, exclusions or had the default_off attribute. That's out of about 125k rules without any of those conditions.
Edit: I added the HTML and JS files I mentioned above to my repo: https://github.com/afarrow/HTTPS-Everywhere-Safari-Test
Having 2 or 3 HTTPS Everywhere extensions would be far better than what we have now, which is nothing.
And as I understand it, the Safari Extension API is consistent across all of Apple’s ecosystem. By making a Safari version, you are also making an iOS version.
@Saklad5 That's correct. A Safari Extension can easily be ported to an iOS App if we use the official API.
Out of curiosity has support been picked up for Safari yet?
@chris1000 not yet, and we don't have rolling out support for safari scheduled. This would involve ensuring that the necessary WebExtensions APIs are supported, in addition to the legal review of their privacy policy.
Hi everyone
I've been working on an iOS app version of HTTPS everywhere. For doing so I've created this script which processes the rulesets to extract a list of hosts that just require a 'simple' redirect: https://gist.github.com/bouk/bc4b1f406c3d4e83d28ade3f1b18a4e0
This list can then be inserted into a rule like
[
{
"action": {
"type": "make-https"
},
"trigger": {
"url-filter": ".*",
"if-domain": [
"*3cdn.net",
"*3scale.net",
etc.
}
]
Which also supports more than the 50k rule limit, it seems there is no limit on the number in if-domain.
It would be good to hunt down overly complicated rulesets, essentially everything generated by make-trivial-rule is supported while others can't be guaranteed
@bouk That’s great! Safari’s content blockers are platform-agnostic as I understand it, so that will work on the Mac too!
Any news/updates about this?
@Revod unfortunately, after legal review we found the Apple Developer License Agreement contains provisos that EFF is unable to comply with. This is for reasons similar to what we stated in this 2014 blog post.
We don't want to encourage others to sign the agreement. Third party implementations of HTTPS Everywhere using our rulesets certainly don't run afoul of our licensing of the project, but there's a caveat.
I'm not a lawyer, but my understanding is that Apple enforces restrictions on redistribution via its Licensing Agreement. So posting the project on the Safari store seems to be a violation of the GPL. So it seems that any contributor who had code merged under the GPL could appeal it's listing in the Safari store. This is an unfortunate outcome of being licensed restrictively, and this has been done in the past.
So I'm not a licensing expert, but I think if anyone chose to list HTTPS Everywhere in the Safari store it would be on shaky grounds.
@Hainish thank you for the reply.
Since the only part of the of the iOS app that would require GPL licensing is the ruleset, which is essentially just a .txt file with a list of hosts, it might be possible to make that file accessible and redistributable from the app, and license the rest of the app under Mozilla Public License. It seems that this would mean that people can redistribute the GPL-licensed part of the app as much as they want. The question is of course whether that's legally sound, or whether having that list of hosts be GPL-licensed means that the whole app needs to be GPL, which we would need legal advice on.
I think I will proceed with that plan, and we'll just see what happens.
@bouk Something that may be helpful here: the way I understand it, the stipulations of the GPL are such that the restrictiveness only applies to code which is included in the same program. This differs from, say, the AGPL, which extends to network interaction. So here's what may interest you:
We plan on delivering the rulesets out-of-band of the extension itself, making it available on the web (along with a signature), so that the mainline HTTPS Everywhere extension as well as any third-party can download and apply these rules. If an iOS extension were to be developed, it could pull in the rulesets (which have been pre-compiled and provided on a webserver) at runtime, and not run afoul of the GPL.
@chris1000 unfortunately it won't be in the same format as iOS content blockers.