Skip to content
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

CSS @import rule breaks morphing model #18

Open
psivesely opened this issue Feb 13, 2018 · 0 comments
Open

CSS @import rule breaks morphing model #18

psivesely opened this issue Feb 13, 2018 · 0 comments
Labels

Comments

@psivesely
Copy link
Member

Summary

Since we only parse the HTML document and not the CSS document(s), which can import more stylesheets into themselves, the page* we think we're creating is not equal to the page the user is actually downloading. Furthermore, any stylesheets imported with @import from other stylesheets will not be padded.

* Page can be defined here as a 3-tuple of values sampled from our distributions: (HTML size scalar, object number scalar, and object size vector).

Background

The CSS @import rule allows you to import one or more style sheets into another.

@import url|string list-of-mediaqueries;
  • url|string: A url or a string representing the location of the resource to import. The url may be absolute or relative.
  • list-of-mediaqueries: A comma-separated list of media queries conditioning the application of the CSS rules defined in the linked URL.

Example

Import the "mobstyle.css" style sheet ONLY if the media is screen and the viewport is maximum 768 pixels:

@import "mobstyle.css" screen and (max-width: 768px);

Background source.

See also the Tor Project onion site.

Solution Proposal

Parse the CSS as part of the HTML morphing process and add any imported stylesheets to the initial page model for morphing. Since "@import rule must be at the top of the document (but after any @charset declaration)," we needn't parse the entire CSS document.

During HTML morphing each CSS object in the HTML page will receive a query string of the form (?...alpaca0=<size 0>&alpaca1=<size 1>...&alpacan=<size n>), where n is the number of @import statements the stylesheet contains. When the CSS object is requested with this string, we will have to morph the CSS to add each of the n query strings to their corresponding imported stylesheets (e.g., @import "mobstyle.css?alpaca=<size 1>"). Then when the substylesheet is requested, we simply pad it to size 1 length.

Of course, we may sometimes need to build a deeper page model if one stylesheet imports another that imports another, and that opens up another set of problems:

  • How do we represent the model?
  • How do we deal with circular imports (how do browsers handle that)?
  • Etc..

For best results, we'll need to study and model the behavior of TBB, so we know which sheets will actually be downloaded. Our algorithm again won't work as expected if we assume all CSS stylesheets will be downloaded, even if the media query arguments ensure it won't in TBB. We'll assume the security slider is set to high and the window size has not been modified for simplicity.

At a later point I intend to introduce memoization for the static content in the creation of page models, so in many cases the overhead of this addition would be minimal.

@psivesely psivesely added the bug label Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant