-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmozilla.patch
332 lines (311 loc) · 13.3 KB
/
mozilla.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -999,7 +999,7 @@ pref("dom.ipc.plugins.sandbox-level.flas
// On windows these levels are:
// See - security/sandbox/win/src/sandboxbroker/sandboxBroker.cpp
// SetSecurityLevelForContentProcess() for what the different settings mean.
-pref("security.sandbox.content.level", 5);
+pref("security.sandbox.content.level", 0);
// This controls the depth of stack trace that is logged when Windows sandbox
// logging is turned on. This is only currently available for the content
diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -238,8 +238,8 @@ pref("dom.webmidi.enabled", false);
// execution to record the bytecode of the JavaScript function used, and save it
// in the existing cache entry. On the following loads of the same script, the
// bytecode would be loaded from the cache instead of being generated once more.
+pref("dom.script_loader.bytecode_cache.enabled", false);
-pref("dom.script_loader.bytecode_cache.enabled", true);
+
// Ignore the heuristics of the bytecode cache, and always record on the first
// visit. (used for testing purposes).
diff --git a/dom/html/HTMLCanvasElement.cpp b/dom/html/HTMLCanvasElement.cpp
--- a/dom/html/HTMLCanvasElement.cpp
+++ b/dom/html/HTMLCanvasElement.cpp
@@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/HTMLCanvasElement.h"
+#include "js/SavedFrameAPI.h"
#include "gfxPrefs.h"
#include "ImageEncoder.h"
@@ -676,26 +675,7 @@ HTMLCanvasElement::ToDataURL(JSContext*
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
+
+ fprintf(stderr, "##########Fingerprinting detected##########\n");
+
+ // JS::RootedString fileName(aCx, JS_GetEmptyString(aCx)), functionName(aCx, JS_GetEmptyString(aCx));
+ uint32_t line = 0;
+ uint32_t column = 0;
+ JS::RootedObject stackp(aCx);
+ if(JS::CaptureCurrentStack(aCx, &stackp)) {
+ JSPrincipals* principals = JS::GetRealmPrincipals(js::GetContextRealm(aCx));
+ if (JS::GetSavedFrameLine(aCx, principals, stackp, &line) == JS::SavedFrameResult::Ok &&
+ JS::GetSavedFrameColumn(aCx, principals, stackp, &column) == JS::SavedFrameResult::Ok &&
+ JS::GetSavedFrameSource(aCx, principals, stackp, &fileName) == JS::SavedFrameResult::Ok) {
+ fprintf(stderr, "%d : %d : %s\n", line, column, JS_EncodeStringToUTF8(aCx, fileName).get());
+ }
+ }
+ // JS::AutoFilename filename;
+ // bool res = DescribeScriptedCaller(aCx, &filename, &line, &column);
+ // fprintf(stderr, "%d : %d : %s\n", line, column, filename.get());
+ // Ends here
+
aRv = ToDataURLImpl(aCx, aSubjectPrincipal, aType, aParams, aDataURL);
}
diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -2115,7 +2124,7 @@ CanvasRenderingContext2D::GetSurfaceForm
void
CanvasRenderingContext2D::Save()
+{ // fprintf(stderr, "**********Fingerprinting possibility**********\n");
+{
EnsureTarget();
if (MOZ_UNLIKELY(!mTarget || mStyleStack.IsEmpty())) {
SetErrorState();
@@ -2134,7 +2143,7 @@ CanvasRenderingContext2D::Save()
void
CanvasRenderingContext2D::Restore()
+{ // fprintf(stderr, "**********Fingerprinting possibility**********\n");
+{
if (MOZ_UNLIKELY(mStyleStack.Length() < 2)) {
return;
}
@@ -4249,9 +4258,7 @@ CanvasRenderingContext2D::DrawOrMeasureT
// replace all the whitespace characters with U+0020 SPACE
nsAutoString textToDraw(aRawText);
TextReplaceWhitespaceCharacters(textToDraw);
+
+ if (textToDraw.Length() > 10)
+ fprintf(stderr, "##########Fingerprinting possibility##########\n");
+
// According to spec, the API should return an empty array if maxWidth was provided
// but is less than or equal to zero or equal to NaN.
if (aMaxWidth.WasPassed() && (aMaxWidth.Value() <= 0 || IsNaN(aMaxWidth.Value()))) {
@@ -5485,9 +5492,7 @@ CanvasRenderingContext2D::GetImageData(J
if (h == 0) {
h = 1;
}
+
+ if (w >= 16 && h >= 16)
+ fprintf(stderr, "********Fingerprinting detected*******\n");
diff --git a/dom/script/ScriptLoader.cpp b/dom/script/ScriptLoader.cpp
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -26,7 +26,6 @@
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/SRILogHelper.h"
+#include <unistd.h>
#include "nsGkAtoms.h"
#include "nsNetUtil.h"
#include "nsIScriptGlobalObject.h"
@@ -495,7 +494,7 @@ ScriptLoader::CreateModuleScript(ModuleL
rv = FillCompileOptionsForRequest(aes, aRequest, global, &options);
if (NS_SUCCEEDED(rv)) {
+ auto srcBuf = GetScriptSource(cx, options.filename(), aRequest);
- auto srcBuf = GetScriptSource(cx, aRequest);
if (srcBuf) {
rv = nsJSUtils::CompileModule(cx, *srcBuf, global, options, &module);
} else {
@@ -1862,7 +1861,7 @@ ScriptLoader::AttemptAsyncScriptCompile(
if (aRequest->IsModuleRequest()) {
MOZ_ASSERT(aRequest->IsTextSource());
+ auto srcBuf = GetScriptSource(cx, options.filename(), aRequest);
- auto srcBuf = GetScriptSource(cx, aRequest);
if (!srcBuf || !JS::CompileOffThreadModule(cx, options,
*srcBuf,
OffThreadScriptLoaderCallback,
@@ -1890,7 +1889,7 @@ ScriptLoader::AttemptAsyncScriptCompile(
#endif
} else {
MOZ_ASSERT(aRequest->IsTextSource());
+ auto srcBuf = GetScriptSource(cx, options.filename(), aRequest);
- auto srcBuf = GetScriptSource(cx, aRequest);
if (!srcBuf || !JS::CompileOffThread(cx, options,
*srcBuf,
OffThreadScriptLoaderCallback,
@@ -1939,9 +1938,12 @@ ScriptLoader::GetScriptSource(JSContext*
{
// Return a SourceBufferHolder object holding the script's source text.
// Ownership of the buffer is transferred to the resulting SourceBufferHolder.
+
+ // If there's no script text, we try to get it from the element
if (aRequest->mIsInline) {
nsAutoString inlineData;
aRequest->Element()->GetScriptText(inlineData);
+
size_t nbytes = inlineData.Length() * sizeof(char16_t);
JS::UniqueTwoByteChars chars(static_cast<char16_t*>(JS_malloc(aCx, nbytes)));
if (!chars) {
@@ -1951,80 +1953,9 @@ ScriptLoader::GetScriptSource(JSContext*
memcpy(chars.get(), inlineData.get(), nbytes);
return Some(SourceBufferHolder(std::move(chars), inlineData.Length()));
}
+
size_t length = aRequest->ScriptText().length();
JS::UniqueTwoByteChars chars(aRequest->ScriptText().extractOrCopyRawBuffer());
+
+ return Some(SourceBufferHolder(std::move(chars), length));
+}
+
+// Write script code to a file
+void writeScriptToFile(JSContext* aCx, bool isInline, const char *filename, const char *str) {
+
+ char result[30];
+ const char* dir = getenv("JS_SCRIPT_OUTDIR");
+ strcpy(result, dir);
+
+ // compile the log file name
+ char n_str[10];
+ sprintf(n_str, "%d.txt", getpid());
+ strcat(result, n_str);
+
+ // compile the script filename
+ JS::UniqueChars chars(static_cast<char*>(JS_malloc(aCx, 22 + strlen(filename) + strlen(str))));
+ if (isInline)
+ strcpy(chars.get(), "\n####In####\n");
+ else
+ strcpy(chars.get(), "\n####Ex####\n");
+ strcpy(chars.get() + 12, filename);
+ strcpy(chars.get() + 12 + strlen(filename), "\n########\n");
+ memcpy(chars.get() + 22 + strlen(filename), str, strlen(str));
+ // Open file in append mode
+ FILE* fp;
+ fp = fopen(result, "a");
+
+ int i = fwrite(chars.get(), /*size=*/ 1, /*nitems=*/ 22 + strlen(filename) + strlen(str), fp);
+
+ fclose(fp);
+ fp = nullptr;
+}
+
+
+mozilla::Maybe<JS::SourceBufferHolder>
+ScriptLoader::GetScriptSource(JSContext* aCx, const char *filename,
+ ScriptLoadRequest* aRequest) {
+ // Return a SourceBufferHolder object holding the script's source text.
+ // Ownership of the buffer is transferred to the resulting SourceBufferHolder.
+ if (aRequest->mIsInline) {
+ nsAutoString inlineData;
+ aRequest->Element()->GetScriptText(inlineData);
+
+ if (strncmp(filename, "http", 4) == 0) {
+ writeScriptToFile(aCx, true, filename, NS_ConvertUTF16toUTF8(inlineData).get());
+ }
+ size_t nbytes = inlineData.Length() * sizeof(char16_t);
+ JS::UniqueTwoByteChars chars(static_cast<char16_t*>(JS_malloc(aCx, nbytes)));
+ if (!chars) {
+ return Nothing();
+ }
-
+ memcpy(chars.get(), inlineData.get(), nbytes);
+ return Some(SourceBufferHolder(std::move(chars), inlineData.Length()));
+ }
+ size_t length = aRequest->ScriptText().length();
+ JS::UniqueTwoByteChars chars(aRequest->ScriptText().extractOrCopyRawBuffer());
-
+ if (strncmp(filename, "http", 4) == 0) {
+ writeScriptToFile(aCx, false, filename, NS_ConvertUTF16toUTF8(chars.get(), length).get());
+ }
+
return Some(SourceBufferHolder(std::move(chars), length));
}
@@ -2472,8 +2401,8 @@ ScriptLoader::EvaluateScript(ScriptLoadR
&script);
} else {
MOZ_ASSERT(aRequest->IsTextSource());
+ auto srcBuf = GetScriptSource(cx, options.filename(), aRequest);
+
- auto srcBuf = GetScriptSource(cx, aRequest);
-
if (srcBuf) {
if (recordreplay::IsRecordingOrReplaying()) {
recordreplay::NoteContentParse16(this, options.filename(), "application/javascript",
diff --git a/dom/script/ScriptLoader.h b/dom/script/ScriptLoader.h
--- a/dom/script/ScriptLoader.h
+++ b/dom/script/ScriptLoader.h
@@ -509,9 +509,6 @@ private:
mozilla::Maybe<JS::SourceBufferHolder> GetScriptSource(JSContext* aCx,
ScriptLoadRequest* aRequest);
+
+ mozilla::Maybe<JS::SourceBufferHolder> GetScriptSource(JSContext* aCx, bool isInline, const char *filename,
+ ScriptLoadRequest* aRequest);
void SetModuleFetchStarted(ModuleLoadRequest *aRequest);
void SetModuleFetchFinishedAndResumeWaitingRequests(ModuleLoadRequest* aRequest,
diff --git a/js/src/builtin/Eval.cpp b/js/src/builtin/Eval.cpp
--- a/js/src/builtin/Eval.cpp
+++ b/js/src/builtin/Eval.cpp
@@ -4,16 +4,15 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#include "builtin/Eval.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/Range.h"
+#include <unistd.h>
#include "frontend/BytecodeCompiler.h"
#include "gc/HashUtil.h"
#include "js/SourceBufferHolder.h"
#include "js/StableStringChars.h"
-
#include "vm/Debugger.h"
#include "vm/GlobalObject.h"
#include "vm/JSContext.h"
@@ -216,31 +215,6 @@ TryEvalJSON(JSContext* cx, JSLinearStrin
: ParseEvalStringAsJSON(cx, linearChars.twoByteRange(), rval);
}
+// Write script code to a file
+void writeScriptToFile(JSContext *aCx, bool isDEval, const char *filename, const char *str) {
+ char result[30];
+ const char* dir = getenv("JS_SCRIPT_OUTDIR");
+ strcpy(result, dir);
+
+ char n_str[10];
+ sprintf(n_str, "%d.txt", getpid());
+ strcat(result, n_str);
+
+ // compile the script filename
+ JS::UniqueChars chars(static_cast<char*>(JS_malloc(aCx, 25 + strlen(filename) + strlen(str))));
+ if (isDEval)
+ strcpy(chars.get(), "\n####DEval####\n");
+ else
+ strcpy(chars.get(), "\n####IEval####\n");
+ strcpy(chars.get() + 15, filename);
+ strcpy(chars.get() + 15 + strlen(filename), "\n########\n");
+ memcpy(chars.get() + 25 + strlen(filename), str, strlen(str));
+
+ FILE* fp;
+ fp = fopen(result, "a");
+ int i = fwrite(chars.get(), /*size=*/ 1, /*nitems=*/ 25 + strlen(filename) + strlen(str), fp);
+ fclose(fp);
+ fp = nullptr;
+}
+
enum EvalType { DIRECT_EVAL, INDIRECT_EVAL };
// Common code implementing direct and indirect eval.
@@ -348,24 +322,6 @@ EvalKernel(JSContext* cx, HandleValue v,
? SourceBufferHolder::GiveOwnership
: SourceBufferHolder::NoOwnership;
SourceBufferHolder srcBuf(chars, linearStr->length(), ownership);
+
+ if (strncmp(filename, "http", 4) == 0) {
+ writeScriptToFile(cx, filename, JS::CharsToNewUTF8CharsZ(cx, linearChars.twoByteRange()).c_str());
+ }
JSScript* compiled = frontend::CompileEvalScript(cx, env, enclosing, options, srcBuf);
if (!compiled) {
return false;
@@ -450,15 +406,6 @@ js::DirectEvalStringFromIon(JSContext* c
? SourceBufferHolder::GiveOwnership
: SourceBufferHolder::NoOwnership;
SourceBufferHolder srcBuf(chars, linearStr->length(), ownership);
+
+ if (strncmp(filename, "http", 4) == 0) {
+ writeScriptToFile(cx, filename, JS::CharsToNewUTF8CharsZ(cx, linearChars.twoByteRange()).c_str());
+ }
JSScript* compiled = frontend::CompileEvalScript(cx, env, enclosing, options, srcBuf);
if (!compiled) {
return false;