Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | const charset = "hz-gb-2312"; |
michael@0 | 2 | |
michael@0 | 3 | function dumpStrings(inString, outString) { |
michael@0 | 4 | var dispIn = ""; |
michael@0 | 5 | var dispOut = ""; |
michael@0 | 6 | var i; |
michael@0 | 7 | for (i = 0; i < inString.length; ++i) { |
michael@0 | 8 | dispIn += " x" + inString.charCodeAt(i).toString(16); |
michael@0 | 9 | } |
michael@0 | 10 | if (outString.length == 0) { |
michael@0 | 11 | dispOut = "<empty>"; |
michael@0 | 12 | } else { |
michael@0 | 13 | for (i = 0; i < outString.length; ++i) { |
michael@0 | 14 | dispOut += " x" + outString.charCodeAt(i).toString(16); |
michael@0 | 15 | } |
michael@0 | 16 | } |
michael@0 | 17 | dump("\"" + dispIn + "\" ==> \"" + dispOut + "\"\n"); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | function error(inString, outString, msg){ |
michael@0 | 21 | dumpStrings(inString, outString); |
michael@0 | 22 | do_throw("security risk: " + msg); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | function run_test() { |
michael@0 | 26 | var ScriptableUnicodeConverter = |
michael@0 | 27 | Components.Constructor("@mozilla.org/intl/scriptableunicodeconverter", |
michael@0 | 28 | "nsIScriptableUnicodeConverter"); |
michael@0 | 29 | |
michael@0 | 30 | var converter = new ScriptableUnicodeConverter(); |
michael@0 | 31 | converter.charset = charset; |
michael@0 | 32 | |
michael@0 | 33 | var leadByte, trailByte; |
michael@0 | 34 | var inString; |
michael@0 | 35 | for (leadByte = 1; leadByte < 0x100; ++leadByte) { |
michael@0 | 36 | for (trailByte = 1; trailByte < 0x100; ++trailByte) { |
michael@0 | 37 | if (leadByte == 0x7e) { |
michael@0 | 38 | if (trailByte == 0x7b || |
michael@0 | 39 | trailByte == 0xa || |
michael@0 | 40 | trailByte == 0x7e) { |
michael@0 | 41 | // ignore escape sequences: |
michael@0 | 42 | // ~{ (sets HZ-GB mode) |
michael@0 | 43 | // ~\n ( ==> \n) |
michael@0 | 44 | // ~~ ( ==> ~) |
michael@0 | 45 | continue; |
michael@0 | 46 | } |
michael@0 | 47 | } |
michael@0 | 48 | inString = String.fromCharCode(leadByte, trailByte, 65); |
michael@0 | 49 | var outString = converter.ConvertToUnicode(inString) + |
michael@0 | 50 | converter.Finish(); |
michael@0 | 51 | switch (outString.length) { |
michael@0 | 52 | case 1: |
michael@0 | 53 | error(inString, outString, "2 byte sequence eaten"); |
michael@0 | 54 | break; |
michael@0 | 55 | case 2: |
michael@0 | 56 | if (outString.charCodeAt(0) < 0x80 && |
michael@0 | 57 | outString.charCodeAt(1) < 0x80) { |
michael@0 | 58 | error(inString, outString, |
michael@0 | 59 | "2 byte sequence converted to 1 ASCII"); |
michael@0 | 60 | } |
michael@0 | 61 | break; |
michael@0 | 62 | case 3: |
michael@0 | 63 | if (outString != inString && |
michael@0 | 64 | outString.charCodeAt(0) < 0x80 && |
michael@0 | 65 | outString.charCodeAt(1) < 0x80) { |
michael@0 | 66 | error(inString, outString, |
michael@0 | 67 | "2 byte sequence converted to 2 ASCII"); |
michael@0 | 68 | } |
michael@0 | 69 | break; |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | } |