-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcookies.js
7784 lines (6702 loc) · 279 KB
/
cookies.js
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 2^25 = 32MB.
// Do not want to test more cookies than that.
var MAX_COOKIE_TEST = 25;
var MAX_RANDOM_COOKIESETS_TEST_ATTEMPTS = 3;
var MAX_NUM_PAGE_LOAD_TIMEOUT_LIMIT = 2;
var MAX_PAGE_LOAD_TIMEOUT_IN_SECONDS_LIMIT = 20;
// **** BEGIN - Dump internal status functions
function onauthrequired_cb(details, my_callback) {
console.log("APPU DEBUG: RequestID: " + details.requestId);
console.log("APPU DEBUG: URL: " + details.url);
console.log("APPU DEBUG: Method: " + details.method);
console.log("APPU DEBUG: FrameID: " + details.frameId);
console.log("APPU DEBUG: Parent FrameID: " + details.parentFrameId);
console.log("APPU DEBUG: Tab ID: " + details.tabId);
console.log("APPU DEBUG: Type: " + details.type);
console.log("APPU DEBUG: Timestamp: " + details.timeStamp);
console.log("APPU DEBUG: Scheme: " + details.scheme);
console.log("APPU DEBUG: Realm: " + details.realm);
console.log("APPU DEBUG: Challenger: " + details.challenger);
console.log("APPU DEBUG: ResponseHeaders: " + details.responseHeaders);
console.log("APPU DEBUG: StatusLine: " + details.statusLine);
}
// This is just a test function
// prints "set-cookie" commands in a HTTP Response.
function cb_headers_received(details) {
if ("responseHeaders" in details) {
var rh = details.responseHeaders;
for (var i = 0; i < rh.length; i++) {
if (rh[i].name.toLowerCase() != "set-cookie") {
continue;
}
console.log("APPU DEBUG: Response Header Name: " + rh[i].name);
if ("value" in rh[i]) {
console.log("APPU DEBUG: Response Header Value: " + rh[i].value);
}
else if ("binaryValue" in rh[i]) {
console.log("APPU DEBUG: Response Header Binary Value: " + rh[i].binaryValue);
}
else {
console.log("APPU DEBUG: Response Header No Value Present");
}
}
}
}
function print_expiry_date(exp_seconds) {
var d = new Date(0);
d.setUTCSeconds(exp_seconds);
console.log("APPU DEBUG: Expiry date for(" + exp_seconds + "): " + d);
}
function get_all_cookies(domain, handle_cookies) {
if(!handle_cookies) {
console.log("APPU DEBUG: handle_cookies() is undefined");
}
chrome.cookies.getAll(
{
'domain' : domain,
},
handle_cookies);
}
function print_appu_session_store_cookies(domain, cookie_class) {
var cs = pii_vault.aggregate_data.session_cookie_store[domain];
var tot_cookies = 0;
var msg = "\n";
for (c in cs.cookies) {
if (cookie_class && (cs.cookies[c].cookie_class == cookie_class)) {
msg += sprintf("(%s) %s,\n", cs.cookies[c].current_state, c);
tot_cookies += 1;
}
else if (cookie_class == undefined) {
msg += sprintf("(%s) %s(%s),\n", cs.cookies[c].current_state, c, cs.cookies[c].cookie_class);
tot_cookies += 1;
}
}
msg = "APPU DEBUG: Domain: " + domain + ", Total-cookies: " + tot_cookies + ", Cookie-names: " + msg;
console.log(msg);
}
function print_confirmed_account_cookies(domain, only_present) {
var cs = pii_vault.aggregate_data.session_cookie_store[domain];
var account_cookies = [];
only_present = (only_present == undefined) ? true : only_present;
for (c in cs.cookies) {
if (cs.cookies[c].is_part_of_account_cookieset == true) {
if (only_present && cs.cookies[c].current_state == "absent") {
continue;
}
account_cookies.push(c);
}
}
print_cookie_values(domain, account_cookies);
}
// Print the cookies discovered in "expand-state" phase
function print_expand_state_cookies(domain, only_present) {
var cs = pii_vault.aggregate_data.session_cookie_store[domain];
var account_cookies = [];
only_present = (only_present == undefined) ? true : only_present;
for (c in cs.cookies) {
if (cs.cookies[c].cookie_class == 'during') {
continue;
}
if (cs.cookies[c].is_part_of_account_cookieset == true) {
if (only_present && cs.cookies[c].current_state == "absent") {
continue;
}
account_cookies.push(c);
}
}
print_cookie_values(domain, account_cookies);
}
function print_account_cookies(domain, only_present) {
var cs = pii_vault.aggregate_data.session_cookie_store[domain];
if (!cs || !cs.cookies) {
console.log("APPU DEBUG: No account cookies detected");
return;
}
var account_cookies = [];
only_present = (only_present == undefined) ? true : only_present;
for (c in cs.cookies) {
if (cs.cookies[c].cookie_class == 'during' ||
cs.cookies[c].is_part_of_account_cookieset == true) {
if (only_present && cs.cookies[c].current_state == "absent") {
continue;
}
account_cookies.push(c);
}
}
print_cookie_values(domain, account_cookies);
}
// Purely for debugging purpose.
// We don't need to actually access the cookie values
// in actual deployments
function print_cookie_values(domain, cookie_names) {
var all_done = [];
var cookie_info = {};
for (var j = 0; j < cookie_names.length; j++) {
all_done[j] = false;
cookie_info[cookie_names[j]] = undefined;
}
chrome.cookies.getAll({
'domain' : domain,
},
(function(cookie_names) {
return function (all_cookies) {
var cs = pii_vault.aggregate_data.session_cookie_store[domain];
for (var i = 0; i < all_cookies.length; i++) {
var cookie_name = all_cookies[i].name;
var cookie_domain = all_cookies[i].domain;
var cookie_path = all_cookies[i].path;
var cookie_protocol = (all_cookies[i].secure) ? "https://" : "http://";
var cookie_key = cookie_protocol + cookie_domain + cookie_path + ":" + cookie_name;
var search_index = cookie_names.indexOf(cookie_key);
if (search_index == -1) {
continue;
}
else {
all_done[search_index] = true;
}
var expiry_time = 'no-expiry-time';
if ('expirationDate' in all_cookies[i]) {
var exp_seconds = all_cookies[i].expirationDate;
var d = new Date(0);
d.setUTCSeconds(exp_seconds);
expiry_time = d.toLocaleString();
}
else {
expiry_time = 'browser-close';
}
var cookie_val = undefined;
try {
cookie_val = decodeURIComponent(all_cookies[i].value);
}
catch(e) {
cookie_val = all_cookies[i].value;
}
//cookie_val = all_cookies[i].value;
var msg = sprintf("Cookie-key: '%s', " +
"\n\tValue-Length: %3d, " +
"HostOnly: '%s', " +
"Secure: '%s', " +
"HttpOnly: '%s', " +
"Session: '%s', " +
"Expiration: '%s', " +
"\n\tValue: '%s', " +
"Appu Class: '%s'",
cookie_key,
all_cookies[i].value.length,
all_cookies[i].hostOnly,
all_cookies[i].secure,
all_cookies[i].httpOnly,
all_cookies[i].session,
expiry_time,
cookie_val,
cs.cookies[cookie_key].cookie_class);
cookie_info[cookie_key] = msg;
if (all_done.indexOf(false) == -1) {
break;
}
}
var found_cookies = Object.keys(cookie_info);
console.log("*****************************");
console.log("APPU DEBUG: Printing all SUSPECTED-ACCOUNT-COOKIES for: " + domain);
var index = 1;
for (var j = 0; j < found_cookies.length; j++) {
if (cookie_info[found_cookies[j]] == undefined) {
continue;
}
console.log((index++) + ". " + cookie_info[found_cookies[j]]);
}
console.log("*****************************");
}
}(cookie_names)));
}
// All cookies related to a particular domain
function print_all_cookies(domain) {
var cb_cookies = (function(domain) {
return function(all_cookies) {
var tot_hostonly = 0;
var tot_httponly = 0;
var tot_secure = 0;
var tot_session = 0;
console.log("*****************************");
console.log("APPU DEBUG: Printing ALL cookies for: " + domain);
for (var i = 0; i < all_cookies.length; i++) {
var cookie_str = "";
var cookie_name = all_cookies[i].name;
var cookie_domain = all_cookies[i].domain;
var cookie_path = all_cookies[i].path;
var cookie_protocol = (all_cookies[i].secure) ? "https://" : "http://";
var cookie_key = cookie_protocol + cookie_domain + cookie_path + ":" + cookie_name;
var expiry_time = 'no-expiry-time';
if ('expirationDate' in all_cookies[i]) {
var exp_seconds = all_cookies[i].expirationDate;
var d = new Date(0);
d.setUTCSeconds(exp_seconds);
expiry_time = d.toLocaleString();
}
else {
expiry_time = 'browser-close';
}
var cookie_val = undefined;
try {
cookie_val = decodeURIComponent(all_cookies[i].value);
}
catch(e) {
cookie_val = all_cookies[i].value;
}
// cookie_val = all_cookies[i].value;
var msg = sprintf("Cookie-key: '%s', " +
"\n\tValue-Length: %3d, " +
"HostOnly: '%s', " +
"Secure: '%s', " +
"HttpOnly: '%s', " +
"Session: '%s', " +
"Expiration: '%s', " +
"\n\tValue: '%s'",
cookie_key,
all_cookies[i].value.length,
all_cookies[i].hostOnly,
all_cookies[i].secure,
all_cookies[i].httpOnly,
all_cookies[i].session,
expiry_time,
cookie_val);
if (all_cookies[i].hostOnly) {
tot_hostonly += 1;
}
if (all_cookies[i].secure) {
tot_secure += 1;
}
if (all_cookies[i].httpOnly) {
tot_httponly += 1;
}
if (all_cookies[i].session) {
tot_session += 1;
}
console.log(i + ". " + msg);
}
console.log("-----------------------------");
console.log("APPU DEBUG: Total HostOnly Cookies: " + tot_hostonly);
console.log("APPU DEBUG: Total HTTPOnly Cookies: " + tot_httponly);
console.log("APPU DEBUG: Total Secure Cookies: " + tot_secure);
console.log("APPU DEBUG: Total Session Cookies: " + tot_session);
console.log("APPU DEBUG: Total number of cookies: " + all_cookies.length);
console.log("*****************************");
}
})(domain);
get_all_cookies(domain, cb_cookies);
}
function print_auth_cookies(domain) {
read_from_local_storage("Auth-Cookie-Equation:" + domain, function(acd) {
acd = acd["Auth-Cookie-Equation:" + domain];
for (var k in acd) {
console.log("APPU DEBUG: Key: " + k + ", value: " + acd[k]);
}
});
}
function compare_auth_cookies(domain) {
read_from_local_storage("Auth-Cookie-Equation:" + domain, function(acd) {
acd = acd["Auth-Cookie-Equation:" + domain];
var f = {};
for (var ck in acd) {
f[ck] = false;
}
var cb_cookies = (function(domain) {
return function(all_cookies) {
for (var i = 0; i < all_cookies.length; i++) {
var cookie_str = "";
var cookie_name = all_cookies[i].name;
var cookie_domain = all_cookies[i].domain;
var cookie_path = all_cookies[i].path;
var cookie_protocol = (all_cookies[i].secure) ? "https://" : "http://";
var cookie_key = cookie_protocol + cookie_domain + cookie_path + ":" + cookie_name;
cookie_val = all_cookies[i].value;
if (cookie_key in acd) {
f[cookie_key] = true;
if (acd[cookie_key] == cookie_val) {
console.log("APPU DEBUG: Values matched for auth-cookie: " + cookie_key);
}
else {
console.log("APPU DEBUG: Values DID NOT match for auth-cookie: " + cookie_key);
}
}
}
for (var ck in f) {
if (f[ck] == false) {
console.log("APPU DEBUG: Did not find auth-cookie: " + ck);
}
}
}
})(domain);
get_all_cookies(domain, cb_cookies);
});
}
// Print all the cookies whose value contain one of the names in PI store.
// Only fields with tags "usernameXXX" and "emailXXX" are checked.
// For emails, check full email and then only anything that comes before "@".
// Any component that is found out should be > 4 characters.
function print_cookies_with_values_containing_usernames(domain) {
var cb_cookies = (function(domain) {
return function(all_cookies) {
var tot_hostonly = 0;
var tot_httponly = 0;
var tot_secure = 0;
var tot_session = 0;
var detected_usernames = {};
var pi_usernames = get_all_values_of_types(["username", "name", "email"], true);
console.log("APPU DEBUG: Printing all cookies containing usernames for: " + domain);
for (var i = 0; i < all_cookies.length; i++) {
for (var j = 0; j < pi_usernames.length; j++) {
if (all_cookies[i].value.indexOf(pi_usernames[j]) != -1) {
detected_usernames[pi_usernames[j]] = true;
var cookie_str = "";
var cookie_name = all_cookies[i].name;
var cookie_domain = all_cookies[i].domain;
var cookie_path = all_cookies[i].path;
var cookie_protocol = (all_cookies[i].secure) ? "https://" : "http://";
var cookie_key = cookie_protocol + cookie_domain + cookie_path + ":" + cookie_name;
cookie_str += "Cookie Key: " + cookie_key;
cookie_str += ", HostOnly: '" + all_cookies[i].hostOnly + "'";
cookie_str += ", Secure: '" + all_cookies[i].secure + "'";
cookie_str += ", HttpOnly: '" + all_cookies[i].httpOnly + "'";
cookie_str += ", Session: '" + all_cookies[i].session + "'";
cookie_str += ", Value: '" + all_cookies[i].value + "'";
cookie_str += ", Expiration: '" + all_cookies[i].expirationDate + "'";
if (all_cookies[i].hostOnly) {
tot_hostonly += 1;
}
if (all_cookies[i].secure) {
tot_secure += 1;
}
if (all_cookies[i].httpOnly) {
tot_httponly += 1;
}
if (all_cookies[i].session) {
tot_session += 1;
}
console.log("APPU DEBUG: " + cookie_str);
break;
}
}
}
console.log("APPU DEBUG: Total HostOnly Cookies: " + tot_hostonly);
console.log("APPU DEBUG: Total HTTPOnly Cookies: " + tot_httponly);
console.log("APPU DEBUG: Total Secure Cookies: " + tot_secure);
console.log("APPU DEBUG: Total Session Cookies: " + tot_session);
console.log("APPU DEBUG: Total number of cookies: " + all_cookies.length);
console.log("APPU DEBUG: Detected usernames: " + JSON.stringify(Object.keys(detected_usernames)));
}
})(domain);
get_all_cookies(domain, cb_cookies);
}
function print_request_body(details) {
if (details.requestBody) {
console.log("APPU DEBUG: Printing request body: " + JSON.stringify(details.requestBody));
}
else {
console.log("APPU DEBUG: No request body is present");
}
}
function print_redirect_information(details) {
if (get_domain(details.redirectUrl.split("/")[2]) != 'live.com') {
console.log("APPU DEBUG: REDIRECT INFO: Current URL: " + details.url +
", FrameID: " + details.frameId +
", type: " + details.type);
console.log("APPU DEBUG: REDIRECT INFO: Redirection URL: " + details.redirectUrl +
", FrameID: " + details.frameId +
", type: " + details.type);
}
}
function print_sent_headers(details) {
if (get_domain(details.url.split("/")[2]) != 'live.com') {
}
}
// Returns all cookies present on disk at this moment across all
// sites.
function count_all_cookies() {
chrome.cookies.getAll({}, function(all_cookies) {
var tot_sites = 0;
var tot_hostonly = 0;
var tot_httponly = 0;
var tot_secure = 0;
var tot_session = 0;
var per_site_cookie_count = {};
for (var i = 0; i < all_cookies.length; i++) {
var cookie_domain = all_cookies[i].domain;
if (cookie_domain[0] == '.') {
cookie_domain = cookie_domain.slice(1, cookie_domain.length);
}
cookie_domain = get_domain(cookie_domain);
if (per_site_cookie_count[cookie_domain] == undefined) {
per_site_cookie_count[cookie_domain] = 1;
tot_sites += 1;
}
else {
per_site_cookie_count[cookie_domain] += 1;
}
if (all_cookies[i].hostOnly) {
tot_hostonly += 1;
}
if (all_cookies[i].secure) {
tot_secure += 1;
}
if (all_cookies[i].httpOnly) {
tot_httponly += 1;
}
if (all_cookies[i].session) {
tot_session += 1;
}
}
var order_by_num_cookies = [];
for (var site in per_site_cookie_count) {
order_by_num_cookies.push([site, per_site_cookie_count[site]]);
}
order_by_num_cookies.sort(function(a, b) {return a[1] - b[1]});
for (var i in order_by_num_cookies) {
console.log("APPU DEBUG: Site: " + order_by_num_cookies[i][0] +
", Cookies: " + order_by_num_cookies[i][1]);
}
console.log("APPU DEBUG: ----------------------------------- ");
console.log("APPU DEBUG: Total HostOnly Cookies: " + tot_hostonly);
console.log("APPU DEBUG: Total HTTPOnly Cookies: " + tot_httponly);
console.log("APPU DEBUG: Total Secure Cookies: " + tot_secure);
console.log("APPU DEBUG: Total Session Cookies: " + tot_session);
console.log("APPU DEBUG: Total Number of Sites: " + tot_sites);
console.log("APPU DEBUG: Total Number of Cookies: " + all_cookies.length);
});
}
function backup_entire_cookiestore(bkupstore_name) {
chrome.cookies.getAll({}, function(all_cookies) {
var data = {};
var bn = "Entire-CookieStore";
if (bkupstore_name != undefined) {
bn = bkupstore_name;
}
data[bn] = {
'cookies' : all_cookies,
};
write_to_local_storage(data);
});
}
function restore_entire_cookiestore(bkupstore_name) {
var bn = "Entire-CookieStore";
if (bkupstore_name != undefined) {
bn = bkupstore_name;
}
var cb = function(cs) {
dump_to_browser_cookie_store(cs[bn]);
console.log("APPU DEBUG: Done restoring the cookie-store ");
}
read_from_local_storage(bn, cb);
}
function expunge_entire_cookiestore(cb) {
chrome.cookies.getAll({}, function(all_cookies) {
for (var i = 0; i < all_cookies.length; i++) {
var protocol = "";
if (all_cookies[i].secure) {
protocol = "https://";
}
else {
protocol = "http://";
}
var url = protocol + all_cookies[i].domain + all_cookies[i].path;
chrome.cookies.remove({
"url": url,
"name": all_cookies[i].name});
}
console.log("APPU DEBUG: Deleted entire cookie store");
if (cb) {
cb();
}
});
}
function delete_entire_cookiestore_from_backup(bkupstore_name) {
var bn;
if (bkupstore_name != undefined) {
bn = bkupstore_name;
} else {
return;
}
for (var i = 0; i < storage_meta.storage_meta.length; i++) {
if (storage_meta.storage_meta[i].indexOf(bn) != -1) {
delete_from_local_storage(storage_meta.storage_meta[i]);
return;
}
}
}
// **** END - Dump internal status functions
// **** BEGIN - Investigation state load/offload functions
// This is to unlimitedStorage.
// None of the sensitive data is stored here.
function delete_pending_cookie_investigation_state(domain) {
for (var i = 0; i < storage_meta.storage_meta.length; i++) {
if (storage_meta.storage_meta[i].indexOf(domain) != -1) {
console.log("APPU DEBUG: Found matching pending cookie investigation state: " + storage_meta.storage_meta[i]);
console.log("APPU DEBUG: Deleting pending cookie investigation state for: " + domain);
delete_from_local_storage(storage_meta.storage_meta[i]);
return;
}
}
console.log("APPU DEBUG: No matching pending cookie investigation state found for: " + domain);
}
function offload_cookie_investigation_state(url, cookie_investigation_state, quiet) {
quiet = (quiet == undefined) ? false : true;
var url_wo_paramters = url.replace(/\?.*/,'');
var data = {};
if (!quiet) {
console.log("APPU DEBUG: Offloading CI state for: " + url_wo_paramters);
}
data["Cookie Investigation State:" + url_wo_paramters] = cookie_investigation_state;
write_to_local_storage(data);
}
function load_cookie_investigation_state(url, cb) {
var url_wo_paramters = url.replace(/\?.*/,'');
console.log("APPU DEBUG: Loading CI state for: " + url_wo_paramters);
if (cb == undefined) {
cb = cb_print("APPU DEBUG: CI state for: " + url + "\n")
}
read_from_local_storage("Cookie Investigation State:" + url_wo_paramters, cb);
}
function remove_cookie_investigation_state(url) {
var url_wo_paramters = url.replace(/\?.*/,'');
console.log("APPU DEBUG: Cleaning CI state for: " + url_wo_paramters);
delete_from_local_storage("Cookie Investigation State:" + url_wo_paramters);
}
function restore_cookie_investigation_state_from_backup(url, backup_name) {
if (backup_name == undefined ||
backup_name == "") {
console.log("APPU DEBUG: Backup name cannot be empty");
return;
}
function restore_backup(state) {
var bn_name = "Cookie Investigation State:" + backup_name;
offload_cookie_investigation_state(url, state[bn_name]);
}
load_cookie_investigation_state(backup_name, restore_backup);
}
function backup_cookie_investigation_state(url, backup_name) {
if (backup_name == undefined ||
backup_name == "") {
console.log("APPU DEBUG: Backup name cannot be empty");
return;
}
function backup(state) {
var url_wo_paramters = url.replace(/\?.*/,'');
url = "Cookie Investigation State:" + url_wo_paramters;
offload_cookie_investigation_state(backup_name, state[url]);
}
load_cookie_investigation_state(url, backup);
}
function modify_cookie_investigation_state(url, modified_values) {
function modify_and_store(obj) {
var url_wo_paramters = url.replace(/\?.*/,'');
var data_key = "Cookie Investigation State:" + url_wo_paramters;
var original_ci_state = obj[data_key];
var modified_properties = Object.keys(modified_values);
for (var i = 0; i < modified_properties.length; i++) {
var p = modified_properties[i];
if (!original_ci_state[p]) {
console.log("APPU DEBUG: Property '" + p +
"' does not exist in the current cookie-investigation state for: " +
url);
}
original_ci_state[p] = modified_values[p];
console.log("APPU DEBUG: Changed property '" + p + "' to '" +
JSON.stringify(original_ci_state[p]) + "' in cookie-investigation state for: " +
url);
}
offload_cookie_investigation_state(url, original_ci_state);
}
load_cookie_investigation_state(url, modify_and_store);
}
function get_enabled_cookies(dca, suspected_account_cookies_array) {
var eca = [];
for (var k = 0; k < suspected_account_cookies_array.length; k++) {
if (dca.indexOf(suspected_account_cookies_array[k]) == -1) {
eca.push(suspected_account_cookies_array[k]);
}
}
return eca;
}
function print_enabled_cookies(cookiesets_array, suspected_account_cookies_array) {
console.log("APPU DEBUG: Enabled cookies in cookiesets-array:");
for (var i = 0; i < cookiesets_array.length; i++) {
var eca = get_enabled_cookies(cookiesets_array[i], suspected_account_cookies_array);
console.log((i+1) + ". Length: " + eca.length + ", Array: " + JSON.stringify(eca));
}
}
function check_sanity_s_na_GUB(s_na_GUB_cookiesets_array, suspected_account_cookies_array) {
var LB_s_na_GUB_decimal_cookiesets = [];
var LB_s_na_GUB_cookiesets_array = [];
for (var i = 0; i < s_na_GUB_cookiesets_array.length; i++) {
var ca = s_na_GUB_cookiesets_array[i];
var rc = convert_cookie_array_to_binary_cookieset(ca, suspected_account_cookies_array, true);
var bc = rc.binary_cookieset;
var dc = rc.decimal_cookieset;
var rc = add_to_set_if_no_subset_member(ca,
LB_s_na_GUB_cookiesets_array,
LB_s_na_GUB_decimal_cookiesets,
suspected_account_cookies_array,
dc);
if (rc[0] == 0) {
console.log("APPU DEBUG: A subset for element at " + i + " is already present at: " + rc[1]);
}
else if (rc[0] == 1 && rc[1].length > 0) {
var sub_elem = get_enabled_cookies(ca, suspected_account_cookies_array);
console.log("APPU DEBUG: Cookieset :" + JSON.stringify(sub_elem));
console.log(" IS subset of: ");
for (var k = 0; k < rc[1].length; k++) {
var e = get_enabled_cookies(s_na_GUB_cookiesets_array[rc[1][k]], suspected_account_cookies_array);
console.log(" Cookieset :" + JSON.stringify(e));
}
}
}
console.log("APPU DEBUG: Original array length: " + s_na_GUB_cookiesets_array.length
+ ", Only subsets array length: " + LB_s_na_GUB_cookiesets_array.length);
if (s_na_GUB_cookiesets_array.length == LB_s_na_GUB_cookiesets_array.length) {
return true;
}
return false;
}
function check_sanity_s_a_GUB(s_a_GUB_cookiesets_array, suspected_account_cookies_array) {
var LB_s_a_GUB_decimal_cookiesets = [];
var LB_s_a_GUB_cookiesets_array = [];
for (var i = 0; i < s_a_GUB_cookiesets_array.length; i++) {
var ca = s_a_GUB_cookiesets_array[i];
var rc = convert_cookie_array_to_binary_cookieset(ca, suspected_account_cookies_array);
var bc = rc.binary_cookieset;
var dc = rc.decimal_cookieset;
add_to_set_if_no_subset_member(ca,
LB_s_a_GUB_cookiesets_array,
LB_s_a_GUB_decimal_cookiesets,
suspected_account_cookies_array,
dc);
}
console.log("APPU DEBUG: Original array length: " + s_a_GUB_cookiesets_array.length
+ ", Only subsets array length: " + LB_s_a_GUB_cookiesets_array.length);
if (s_a_GUB_cookiesets_array.length == LB_s_a_GUB_cookiesets_array.length) {
return true;
}
return false;
}
// Print all cookiesets that have been tested so far for a URL
function print_cookie_investigation_state(url) {
function process_state(state) {
var url_wo_paramters = url.replace(/\?.*/,'');
url = "Cookie Investigation State:" + url_wo_paramters;
if (state == undefined ||
JSON.stringify(state) == JSON.stringify({})) {
console.log("APPU DEBUG: State is not detected for URL: " + url);
return;
}
var expand_state_discovered_cookies = JSON.parse(state[url]["expand_state_discovered_cookies"]);
var on_disk_s_a_LLB_cookiesets_array = state[url]["on_disk_s_a_LLB_cookiesets_array"];
var on_disk_s_na_LLB_cookiesets_array = state[url]["on_disk_s_na_LLB_cookiesets_array"];
var on_disk_s_a_GUB_cookiesets_array = state[url]["on_disk_s_a_GUB_cookiesets_array"];
var on_disk_s_na_GUB_cookiesets_array = state[url]["on_disk_s_na_GUB_cookiesets_array"];
var on_disk_ns_na_LLB_cookiesets_array = state[url]["on_disk_ns_na_LLB_cookiesets_array"];
var on_disk_ns_a_GUB_cookiesets_array = state[url]["on_disk_ns_a_GUB_cookiesets_array"];
var suspected_account_cookies_array = state[url]["suspected_account_cookies_array"];
var non_suspected_account_cookies_array = state[url]["non_suspected_account_cookies_array"];
var tot_time_taken = state[url]["tot_time_taken"];
var tot_bytes_sent = state[url]["tot_bytes_sent"];
var tot_bytes_recvd = state[url]["tot_bytes_recvd"];
var tot_time_since_last_lo_change = state[url]["tot_time_since_last_lo_change"];
var tot_attempts = state[url]["tot_attempts"];
var tot_page_reloads_overall = state[url]["tot_page_reloads_overall"];
var tot_page_reloads_naive = state[url]["tot_page_reloads_naive"];
var tot_page_reloads_since_last_lo_change = state[url]["tot_page_reloads_since_last_lo_change"];
var tot_cookiesets_tested_overall = state[url]["tot_cookiesets_tested_overall"];
var tot_gub_cookiesets_tested_overall = state[url]["tot_gub_cookiesets_tested_overall"];
var cookiesets_optimization_stats = state[url]["cookiesets_optimization_stats"];
var tot_expand_state_cookiesets_tested_overall = state[url]["tot_expand_state_cookiesets_tested_overall"];
var tot_expand_state_entered = state[url]["tot_expand_state_entered"];
var num_cookies_drop_for_round = state[url]["num_cookies_drop_for_round"];
var num_cookies_pass_for_round = state[url]["num_cookies_pass_for_round"];
var curr_llb_cookieset_array = state[url]["curr_llb_cookieset_array"];
var curr_binary_cs = undefined;
if (curr_llb_cookieset_array) {
curr_binary_cs = convert_cookie_array_to_binary_cookieset(curr_llb_cookieset_array,
suspected_account_cookies_array);
}
var curr_gub_cookieset_array = state[url]["curr_gub_cookieset_array"];
var curr_gub_binary_cs = undefined;
if (curr_gub_cookieset_array) {
curr_gub_binary_cs = convert_cookie_array_to_binary_cookieset(curr_gub_cookieset_array,
suspected_account_cookies_array);
}
var next_llb_cookieset_array = state[url]["next_llb_cookieset_array"];
var next_binary_cs = undefined;
if (next_llb_cookieset_array) {
next_binary_cs = convert_cookie_array_to_binary_cookieset(next_llb_cookieset_array,
suspected_account_cookies_array);
}
var next_gub_cookieset_array = state[url]["next_gub_cookieset_array"];
var next_gub_binary_cs = undefined;
if (next_gub_cookieset_array) {
next_gub_binary_cs = convert_cookie_array_to_binary_cookieset(next_gub_cookieset_array,
suspected_account_cookies_array);
}
console.log("APPU DEBUG: suspected_account_cookies_array length: " +
suspected_account_cookies_array.length);
console.log("-------------------");
for (var i = 0; i < suspected_account_cookies_array.length; i++) {
console.log((i+1) + ". " + suspected_account_cookies_array[i]);
}
console.log("-------------------");
console.log("");
console.log("");
console.log("-------------------");
console.log("APPU DEBUG: non_suspected_account_cookies_array length: " +
non_suspected_account_cookies_array.length);
for (var i = 0; i < non_suspected_account_cookies_array.length; i++) {
console.log((i+1) + ". " + non_suspected_account_cookies_array[i]);
}
console.log("-------------------");
console.log("APPU DEBUG: Last num_cookies_drop_for_round " + num_cookies_drop_for_round);
console.log("APPU DEBUG: Last num_cookies_pass_for_round " + num_cookies_pass_for_round);
if (curr_llb_cookieset_array) {
console.log("APPU DEBUG: curr_llb_cookieset_array: " + JSON.stringify(curr_llb_cookieset_array));
console.log("APPU DEBUG: curr_binary_cs: " + JSON.stringify(curr_binary_cs.binary_cookieset));
console.log("APPU DEBUG: curr_decimal_cs: " + JSON.stringify(curr_binary_cs.decimal_cookieset));
}
if (curr_gub_cookieset_array) {
console.log("APPU DEBUG: curr_gub_cookieset_array: " + JSON.stringify(curr_gub_cookieset_array));
console.log("APPU DEBUG: curr_gub_binary_cs: " + JSON.stringify(curr_gub_binary_cs.binary_cookieset));
console.log("APPU DEBUG: curr_gub_decimal_cs: " + JSON.stringify(curr_gub_binary_cs.decimal_cookieset));
}
if (next_llb_cookieset_array) {
console.log("APPU DEBUG: next_llb_cookieset_array: " + JSON.stringify(next_llb_cookieset_array));
console.log("APPU DEBUG: next_binary_cs: " + JSON.stringify(next_binary_cs.binary_cookieset));
console.log("APPU DEBUG: next_decimal_cs: " + JSON.stringify(next_binary_cs.decimal_cookieset));
}
if (next_gub_cookieset_array) {
console.log("APPU DEBUG: next_gub_cookieset_array: " + JSON.stringify(next_gub_cookieset_array));
console.log("APPU DEBUG: next_gub_binary_cs: " + JSON.stringify(next_gub_binary_cs.binary_cookieset));
console.log("APPU DEBUG: next_gub_decimal_cs: " + JSON.stringify(next_gub_binary_cs.decimal_cookieset));
}
console.log("APPU DEBUG: LLBs in suspected that cause logouts (Used for optimization): " +
on_disk_s_a_LLB_cookiesets_array.length);
console.log("APPU DEBUG: GUBs in suspected that *DO NOT* cause logouts (Used for optimization): " +
on_disk_s_na_GUB_cookiesets_array.length);
console.log("");
console.log("APPU DEBUG: LLBs in suspected that *DO NOT* cause logouts (Wasted testing effort): " +
on_disk_s_na_LLB_cookiesets_array.length);
console.log("APPU DEBUG: GUBs in suspected that cause logouts (Wasted testing effort): " +
on_disk_s_a_GUB_cookiesets_array.length);
console.log("");
console.log("EXPAND-STATE COOKIESET TESTING:");
console.log("APPU DEBUG: LLBs in non-suspected that *DO NOT* cause logouts: " +
on_disk_ns_na_LLB_cookiesets_array.length);
console.log("APPU DEBUG: GUBs in non-suspected that cause logouts: " +
on_disk_ns_a_GUB_cookiesets_array.length);
console.log("");
console.log("BANDWIDTH: ");
console.log("APPU DEBUG: Total bytes sent during investigation: " + get_human_readable_size(tot_bytes_sent));
console.log("APPU DEBUG: Total bytes received during investigation: " + get_human_readable_size(tot_bytes_recvd));
console.log("");
console.log("TIME: ");
console.log("APPU DEBUG: Total time taken for investigation so far: " + Math.floor((tot_time_taken/60)) + "m " +
Math.floor((tot_time_taken % 60)) + "s");
console.log("APPU DEBUG: Total time in generating cookiesets: " +
tot_time_since_last_lo_change);
console.log("");
console.log("ATTEMPTS & PAGE-FETCHES: ");
console.log("APPU DEBUG: Total attempts so far: " + tot_attempts);
console.log("APPU DEBUG: Total page reloads so far: " + tot_page_reloads_overall);
console.log("APPU DEBUG: Total page reloads naive method so far: " + tot_page_reloads_naive);
console.log("APPU DEBUG: Total times expand-state entered: " + tot_expand_state_entered);
console.log("");
console.log("COOKIESETS STATS: ");
console.log("APPU DEBUG: Expand-state cookiesets: " + tot_expand_state_cookiesets_tested_overall);
console.log("APPU DEBUG: GUB cookiesets: " + tot_gub_cookiesets_tested_overall);
console.log("APPU DEBUG: Total cookiesets: " + tot_cookiesets_tested_overall);
console.log("");
console.log("");
console.log("");
console.log("-------------------");
console.log("APPU DEBUG: Number of cookies discovered in past expand-states: " +
expand_state_discovered_cookies.length);
console.log("APPU DEBUG: Cookies discovered in past EXPAND-STATES: ");
for (var i = 0; i < expand_state_discovered_cookies.length; i++) {
console.log((i+1) + ". " + expand_state_discovered_cookies[i]);
console.log("");
}
console.log("-------------------");
console.log("");
console.log("");
console.log("");
console.log("-------------------");
console.log("APPU DEBUG: LLBs in suspected that cause logouts (Used in optimization): " +
on_disk_s_a_LLB_cookiesets_array.length);
for (var i = 0; i < on_disk_s_a_LLB_cookiesets_array.length; i++) {
console.log((i+1) + ". " + JSON.stringify(on_disk_s_a_LLB_cookiesets_array[i]));
console.log("");
}
console.log("-------------------");
console.log("");
console.log("");
console.log("");
console.log("-------------------");
console.log("APPU DEBUG: GUBs in suspected that *DO NOT* cause logouts (Used in optimization): " +
on_disk_s_na_GUB_cookiesets_array.length);