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

fingerprinting protection #44

Merged
merged 4 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
diff --git a/third_party/WebKit/Source/modules/canvas/canvas2d/BaseRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas/canvas2d/BaseRenderingContext2D.cpp
index d40e8da53aa03c00ef27fb22141105db0b9bad6b..43dfa8385661dc93c4e071a65430e8c43fe6bccc 100644
--- a/third_party/WebKit/Source/modules/canvas/canvas2d/BaseRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/modules/canvas/canvas2d/BaseRenderingContext2D.cpp
@@ -6,9 +6,11 @@

#include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "brave/renderer/brave_content_settings_observer_helper.h"
#include "core/css/cssom/CSSURLImageValue.h"
#include "core/css/parser/CSSParser.h"
#include "core/dom/ExecutionContext.h"
+#include "core/frame/LocalDOMWindow.h"
#include "core/html/HTMLImageElement.h"
#include "core/html/canvas/HTMLCanvasElement.h"
#include "core/html/canvas/ImageData.h"
@@ -349,7 +351,12 @@ void BaseRenderingContext2D::setShadowColor(const String& color_string) {
ModifiableState().SetShadowColor(color.Rgb());
}

-const Vector<double>& BaseRenderingContext2D::getLineDash() const {
+const Vector<double>& BaseRenderingContext2D::getLineDash(ScriptState* script_state) const {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per slack discussion with @bridiver, move canvas blocking into BaseRenderingContext2D to cover OffscreenCanvasRenderingContext2D & PaintRenderingContext2D.

+ static const Vector<double> emptyVector;
+ LocalDOMWindow* window = LocalDOMWindow::From(script_state);
+ if (window && !AllowFingerprinting(window->GetFrame())) {
+ return emptyVector;
+ }
return GetState().LineDash();
}

@@ -744,16 +751,26 @@ void BaseRenderingContext2D::clip(Path2D* dom_path,
ClipInternal(dom_path->GetPath(), winding_rule_string);
}

-bool BaseRenderingContext2D::isPointInPath(const double x,
+bool BaseRenderingContext2D::isPointInPath(ScriptState* script_state,
+ const double x,
const double y,
const String& winding_rule_string) {
+ LocalDOMWindow* window = LocalDOMWindow::From(script_state);
+ if (window && !AllowFingerprinting(window->GetFrame())) {
+ return false;
+ }
return IsPointInPathInternal(path_, x, y, winding_rule_string);
}

-bool BaseRenderingContext2D::isPointInPath(Path2D* dom_path,
+bool BaseRenderingContext2D::isPointInPath(ScriptState* script_state,
+ Path2D* dom_path,
const double x,
const double y,
const String& winding_rule_string) {
+ LocalDOMWindow* window = LocalDOMWindow::From(script_state);
+ if (window && !AllowFingerprinting(window->GetFrame())) {
+ return false;
+ }
return IsPointInPathInternal(dom_path->GetPath(), x, y, winding_rule_string);
}

@@ -778,13 +795,22 @@ bool BaseRenderingContext2D::IsPointInPathInternal(
SkFillTypeToWindRule(ParseWinding(winding_rule_string)));
}

-bool BaseRenderingContext2D::isPointInStroke(const double x, const double y) {
+bool BaseRenderingContext2D::isPointInStroke(ScriptState* script_state, const double x, const double y) {
+ LocalDOMWindow* window = LocalDOMWindow::From(script_state);
+ if (window && !AllowFingerprinting(window->GetFrame())) {
+ return false;
+ }
return IsPointInStrokeInternal(path_, x, y);
}

-bool BaseRenderingContext2D::isPointInStroke(Path2D* dom_path,
+bool BaseRenderingContext2D::isPointInStroke(ScriptState* script_state,
+ Path2D* dom_path,
const double x,
const double y) {
+ LocalDOMWindow* window = LocalDOMWindow::From(script_state);
+ if (window && !AllowFingerprinting(window->GetFrame())) {
+ return false;
+ }
return IsPointInStrokeInternal(dom_path->GetPath(), x, y);
}

@@ -1520,11 +1546,14 @@ ImageData* BaseRenderingContext2D::createImageData(
}

ImageData* BaseRenderingContext2D::getImageData(
+ ScriptState* script_state,
int sx,
int sy,
int sw,
int sh,
ExceptionState& exception_state) {
+ LocalDOMWindow* window = LocalDOMWindow::From(script_state);
+ if (window && !AllowFingerprinting(window->GetFrame())) return nullptr;
if (!WTF::CheckMul(sw, sh).IsValid<int>()) {
exception_state.ThrowRangeError("Out of memory at ImageData creation");
return nullptr;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/third_party/WebKit/Source/modules/canvas/canvas2d/BaseRenderingContext2D.h b/third_party/WebKit/Source/modules/canvas/canvas2d/BaseRenderingContext2D.h
index a217c9778926db44c42b4abe2e9a40fa8dd78e3c..b884dd769b3b66340c89175ab41a31ffb002d694 100644
--- a/third_party/WebKit/Source/modules/canvas/canvas2d/BaseRenderingContext2D.h
+++ b/third_party/WebKit/Source/modules/canvas/canvas2d/BaseRenderingContext2D.h
@@ -57,7 +57,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
double miterLimit() const;
void setMiterLimit(double);

- const Vector<double>& getLineDash() const;
+ const Vector<double>& getLineDash(ScriptState*) const;
void setLineDash(const Vector<double>&);

double lineDashOffset() const;
@@ -116,15 +116,17 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
void clip(const String& winding = "nonzero");
void clip(Path2D*, const String& winding = "nonzero");

- bool isPointInPath(const double x,
+ bool isPointInPath(ScriptState*,
+ const double x,
const double y,
const String& winding = "nonzero");
- bool isPointInPath(Path2D*,
+ bool isPointInPath(ScriptState*,
+ Path2D*,
const double x,
const double y,
const String& winding = "nonzero");
- bool isPointInStroke(const double x, const double y);
- bool isPointInStroke(Path2D*, const double x, const double y);
+ bool isPointInStroke(ScriptState*, const double x, const double y);
+ bool isPointInStroke(ScriptState*, Path2D*, const double x, const double y);

void clearRect(double x, double y, double width, double height);
void fillRect(double x, double y, double width, double height);
@@ -201,7 +203,7 @@ class MODULES_EXPORT BaseRenderingContext2D : public GarbageCollectedMixin,
ImageDataColorSettings&,
ExceptionState&) const;

- ImageData* getImageData(int sx, int sy, int sw, int sh, ExceptionState&);
+ ImageData* getImageData(ScriptState*, int sx, int sy, int sw, int sh, ExceptionState&);
void putImageData(ImageData*, int dx, int dy, ExceptionState&);
void putImageData(ImageData*,
int dx,
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/third_party/WebKit/Source/modules/canvas/canvas2d/CanvasRenderingContext2D.cpp b/third_party/WebKit/Source/modules/canvas/canvas2d/CanvasRenderingContext2D.cpp
index 94de909f954d2f4638a89aa37575e39626989ae8..76a8211b23d69ef4efe070baa2d7153af82bc355 100644
index 94de909f954d2f4638a89aa37575e39626989ae8..6760f73fc6dfda85c060e48521fa901b654befad 100644
--- a/third_party/WebKit/Source/modules/canvas/canvas2d/CanvasRenderingContext2D.cpp
+++ b/third_party/WebKit/Source/modules/canvas/canvas2d/CanvasRenderingContext2D.cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this also need to block getImageData and getLineDash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I missed these two methods in the first place, thanks for pointing it out!

@@ -36,6 +36,7 @@
Expand All @@ -20,56 +20,3 @@ index 94de909f954d2f4638a89aa37575e39626989ae8..76a8211b23d69ef4efe070baa2d7153a
canvas()->GetDocument().UpdateStyleAndLayoutTreeForNode(canvas());

const Font& font = AccessFont();
@@ -778,6 +782,52 @@ TextMetrics* CanvasRenderingContext2D::measureText(const String& text) {
GetState().GetTextAlign(), text);
}

+bool CanvasRenderingContext2D::isPointInPath(const double x,
+ const double y,
+ const String& winding_rule_string) {
+ if (!AllowFingerprinting(canvas()->GetDocument().GetFrame())) return false;
+ return BaseRenderingContext2D::isPointInPath(x, y, winding_rule_string);
+}
+
+bool CanvasRenderingContext2D::isPointInPath(Path2D* dom_path,
+ const double x,
+ const double y,
+ const String& winding_rule_string) {
+ if (!AllowFingerprinting(canvas()->GetDocument().GetFrame())) return false;
+ return BaseRenderingContext2D::isPointInPath(dom_path, x, y,
+ winding_rule_string);
+}
+
+bool CanvasRenderingContext2D::isPointInStroke(const double x, const double y) {
+ if (!AllowFingerprinting(canvas()->GetDocument().GetFrame())) return false;
+ return BaseRenderingContext2D::isPointInStroke(x, y);
+}
+
+bool CanvasRenderingContext2D::isPointInStroke(Path2D* dom_path,
+ const double x,
+ const double y) {
+ if (!AllowFingerprinting(canvas()->GetDocument().GetFrame())) return false;
+ return BaseRenderingContext2D::isPointInStroke(dom_path, x, y);
+}
+
+ImageData* CanvasRenderingContext2D::getImageData(
+ int sx,
+ int sy,
+ int sw,
+ int sh,
+ ExceptionState& exception_state) {
+ if (!AllowFingerprinting(canvas()->GetDocument().GetFrame())) return nullptr;
+ return BaseRenderingContext2D::getImageData(sx, sy, sw, sh, exception_state);
+}
+
+const Vector<double>& CanvasRenderingContext2D::getLineDash() const {
+ static const Vector<double> emptyVector;
+ if (!AllowFingerprinting(canvas()->GetDocument().GetFrame())) {
+ return emptyVector;
+ }
+ return BaseRenderingContext2D::getLineDash();
+}
+
void CanvasRenderingContext2D::DrawTextInternal(
const String& text,
double x,

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/third_party/WebKit/Source/modules/canvas/canvas2d/CanvasRenderingContext2D.idl b/third_party/WebKit/Source/modules/canvas/canvas2d/CanvasRenderingContext2D.idl
index b578065ce53224fa0f3f5ed9369dca8bc3a730ec..696b097bfaef3a8a42c4f3f72120d361f766fa1d 100644
--- a/third_party/WebKit/Source/modules/canvas/canvas2d/CanvasRenderingContext2D.idl
+++ b/third_party/WebKit/Source/modules/canvas/canvas2d/CanvasRenderingContext2D.idl
@@ -102,10 +102,10 @@ interface CanvasRenderingContext2D {
[RuntimeEnabled=ExperimentalCanvasFeatures] void scrollPathIntoView(optional Path2D path);
void clip(optional CanvasFillRule winding);
void clip(Path2D path, optional CanvasFillRule winding);
- boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- boolean isPointInStroke(unrestricted double x, unrestricted double y);
- boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState] boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState] boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState] boolean isPointInStroke(unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);

// text (see also the CanvasDrawingStyles interface)
void fillText(DOMString text, unrestricted double x, unrestricted double y, optional unrestricted double maxWidth);
@@ -125,7 +125,7 @@ interface CanvasRenderingContext2D {
// pixel manipulation
[RaisesException] ImageData createImageData(ImageData imagedata);
[RaisesException] ImageData createImageData(long sw, long sh);
- [RaisesException] ImageData getImageData(long sx, long sy, long sw, long sh);
+ [CallWith=ScriptState, RaisesException] ImageData getImageData(long sx, long sy, long sw, long sh);
[RaisesException] void putImageData(ImageData imagedata, long dx, long dy);
[RaisesException] void putImageData(ImageData imagedata, long dx, long dy, long dirtyX, long dirtyY, long dirtyWidth, long dirtyHeight);

@@ -148,6 +148,7 @@ interface CanvasRenderingContext2D {

// dashed lines
void setLineDash(sequence<unrestricted double> dash);
+ [CallWith=ScriptState]
sequence<unrestricted double> getLineDash();
attribute unrestricted double lineDashOffset;

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/third_party/WebKit/Source/modules/canvas/offscreencanvas2d/OffscreenCanvasRenderingContext2D.idl b/third_party/WebKit/Source/modules/canvas/offscreencanvas2d/OffscreenCanvasRenderingContext2D.idl
index 227586a9f79859a5c27c73e94f2d34d7ac357962..b5a930c192a01a7965492a542408cc63000e67b1 100644
--- a/third_party/WebKit/Source/modules/canvas/offscreencanvas2d/OffscreenCanvasRenderingContext2D.idl
+++ b/third_party/WebKit/Source/modules/canvas/offscreencanvas2d/OffscreenCanvasRenderingContext2D.idl
@@ -60,10 +60,10 @@
void stroke(Path2D path);
void clip();
void clip(Path2D path);
- boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- boolean isPointInStroke(unrestricted double x, unrestricted double y);
- boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState] boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState] boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState] boolean isPointInStroke(unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);

// text (see also the CanvasDrawingStyles interface)
void fillText(DOMString text, unrestricted double x, unrestricted double y, optional unrestricted double maxWidth);
@@ -78,7 +78,7 @@
// pixel manipulation
[RaisesException] ImageData createImageData(ImageData imagedata);
[RaisesException] ImageData createImageData(long sw, long sh);
- [RaisesException] ImageData getImageData(long sx, long sy, long sw, long sh);
+ [CallWith=ScriptState, RaisesException] ImageData getImageData(long sx, long sy, long sw, long sh);
[RaisesException] void putImageData(ImageData imagedata, long dx, long dy);
[RaisesException] void putImageData(ImageData imagedata, long dx, long dy, long dirtyX, long dirtyY, long dirtyWidth, long dirtyHeight);

@@ -96,7 +96,7 @@

// dashed lines
void setLineDash(sequence<unrestricted double> dash);
- sequence<unrestricted double> getLineDash();
+ [CallWith=ScriptState] sequence<unrestricted double> getLineDash();
attribute unrestricted double lineDashOffset;

// text
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/third_party/WebKit/Source/modules/csspaint/PaintRenderingContext2D.idl b/third_party/WebKit/Source/modules/csspaint/PaintRenderingContext2D.idl
index 9edfdb35bc6648b5ede702c90c7bebc99089fe4c..471c84b08feebba19f674445f153f1713ddaa8e6 100644
--- a/third_party/WebKit/Source/modules/csspaint/PaintRenderingContext2D.idl
+++ b/third_party/WebKit/Source/modules/csspaint/PaintRenderingContext2D.idl
@@ -57,10 +57,10 @@

void clip(optional CanvasFillRule winding);
void clip(Path2D path, optional CanvasFillRule winding);
- boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
- boolean isPointInStroke(unrestricted double x, unrestricted double y);
- boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState] boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState] boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule winding);
+ [CallWith=ScriptState] boolean isPointInStroke(unrestricted double x, unrestricted double y);
+ [CallWith=ScriptState] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);

// drawing images
[CallWith=ScriptState, RaisesException] void drawImage(CanvasImageSource image, unrestricted double x, unrestricted double y);
@@ -76,7 +76,7 @@

// dashed lines
void setLineDash(sequence<unrestricted double> dash);
- sequence<unrestricted double> getLineDash();
+ [CallWith=ScriptState] sequence<unrestricted double> getLineDash();
attribute unrestricted double lineDashOffset;
};
PaintRenderingContext2D implements CanvasPath;