diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-01-21 22:34:33 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2012-01-21 22:34:33 +0100 |
commit | e7b4b73969b02708142321001c1979f0c398ef8e (patch) | |
tree | 57991de5daf924d65f00cae2509b7c72d5c78b0a /src | |
parent | ca3f6616f18019feec480af2e4d5898bad3969d0 (diff) |
ignore remote CSS rules that could reveal browser history
For a discussion of the problem see:
http://dbaron.org/mozilla/visited-privacy
Diffstat (limited to 'src')
-rw-r--r-- | src/css.cc | 20 | ||||
-rw-r--r-- | src/css.hh | 7 |
2 files changed, 26 insertions, 1 deletions
@@ -27,6 +27,7 @@ CssPropertyList::CssPropertyList (const CssPropertyList &p, bool deep) : lout::misc::SimpleVector <CssProperty> (p) { refCount = 0; + safe = p.safe; if (deep) { for (int i = 0; i < size (); i++) { CssProperty *p = getRef(i); @@ -58,6 +59,9 @@ void CssPropertyList::set (CssPropertyName name, CssValueType type, CssPropertyValue value) { CssProperty *prop; + if (name == CSS_PROPERTY_DISPLAY || name == CSS_PROPERTY_BACKGROUND_IMAGE) + safe = false; + for (int i = 0; i < size (); i++) { prop = getRef (i); @@ -169,6 +173,13 @@ void CssSelector::addSimpleSelector (Combinator c) { cs->selector = new CssSimpleSelector (); } +bool CssSelector::checksPseudoClass () { + for (int i = 0; i < selectorList->size (); i++) + if (selectorList->getRef (i)->selector->getPseudoClass ()) + return true; + return false; +} + /** * \brief Return the specificity of the selector. * @@ -517,6 +528,13 @@ void CssContext::addRule (CssSelector *sel, CssPropertyList *props, if (props->size () > 0) { CssRule *rule = new CssRule (sel, props, pos++); - sheet[order].addRule (rule); + if ((order == CSS_PRIMARY_AUTHOR || + order == CSS_PRIMARY_AUTHOR_IMPORTANT) && + !rule->isSafe ()) { + MSG_WARN ("Ignoring unsafe author style that might reveal browsing history\n"); + delete rule; + } else { + sheet[order].addRule (rule); + } } } @@ -297,11 +297,13 @@ class CssProperty { class CssPropertyList : public lout::misc::SimpleVector <CssProperty> { int refCount; bool ownerOfStrings; + bool safe; public: inline CssPropertyList(bool ownerOfStrings = false) : lout::misc::SimpleVector <CssProperty> (1) { refCount = 0; + safe = true; this->ownerOfStrings = ownerOfStrings; }; CssPropertyList(const CssPropertyList &p, bool deep = false); @@ -310,6 +312,7 @@ class CssPropertyList : public lout::misc::SimpleVector <CssProperty> { void set (CssPropertyName name, CssValueType type, CssPropertyValue value); void apply (CssPropertyList *props); + bool isSafe () { return safe; }; void print (); inline void ref () { refCount++; } inline void unref () { if (--refCount == 0) delete this; } @@ -385,6 +388,7 @@ class CssSelector { return match (dt, node, selectorList->size () - 1, COMB_NONE); }; int specificity (); + bool checksPseudoClass (); void print (); inline void ref () { refCount++; } inline void unref () { if (--refCount == 0) delete this; } @@ -408,6 +412,9 @@ class CssRule { void apply (CssPropertyList *props, Doctree *docTree, const DoctreeNode *node); + inline bool isSafe () { + return !selector->checksPseudoClass () || props->isSafe (); + }; inline int specificity () { return spec; }; inline int position () { return pos; }; void print (); |