[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor-browser/tor-browser-68.2.0esr-9.5-1] Bug 1534339 - make OriginAttributes deserializable; r=baku
commit 6dfcb949b8375614b588a191035c5cc36fa3e943
Author: Liang-Heng Chen <xeonchen@xxxxxxxxx>
Date: Wed Oct 23 14:10:19 2019 +0000
Bug 1534339 - make OriginAttributes deserializable; r=baku
`CreateSuffix` is irreversible by `PopulateFromSuffix` because it uses a multi-to-one mapping.
Since only ':' will happen in a IPv6 format, we can make it a 1-to-1 mapping so that the `firstPartyDomain` is consistent after `CreateSuffix` and `PopulateFromSuffix`.
Differential Revision: https://phabricator.services.mozilla.com/D47910
--HG--
extra : moz-landing-system : lando
---
caps/OriginAttributes.cpp | 10 +++++++---
caps/tests/gtest/TestOriginAttributes.cpp | 2 ++
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/caps/OriginAttributes.cpp b/caps/OriginAttributes.cpp
index 0737bce36321..e987f0e4fc2e 100644
--- a/caps/OriginAttributes.cpp
+++ b/caps/OriginAttributes.cpp
@@ -13,6 +13,9 @@
#include "nsIURI.h"
#include "nsURLHelper.h"
+static const char kSourceChar = ':';
+static const char kSanitizedChar = '+';
+
namespace mozilla {
using dom::URLParams;
@@ -158,8 +161,7 @@ void OriginAttributes::CreateSuffix(nsACString& aStr) const {
if (!mFirstPartyDomain.IsEmpty()) {
nsAutoString sanitizedFirstPartyDomain(mFirstPartyDomain);
- sanitizedFirstPartyDomain.ReplaceChar(
- dom::quota::QuotaManager::kReplaceChars, '+');
+ sanitizedFirstPartyDomain.ReplaceChar(kSourceChar, kSanitizedChar);
params.Set(NS_LITERAL_STRING("firstPartyDomain"),
sanitizedFirstPartyDomain);
@@ -246,7 +248,9 @@ class MOZ_STACK_CLASS PopulateFromSuffixIterator final
if (aName.EqualsLiteral("firstPartyDomain")) {
MOZ_RELEASE_ASSERT(mOriginAttributes->mFirstPartyDomain.IsEmpty());
- mOriginAttributes->mFirstPartyDomain.Assign(aValue);
+ nsAutoString firstPartyDomain(aValue);
+ firstPartyDomain.ReplaceChar(kSanitizedChar, kSourceChar);
+ mOriginAttributes->mFirstPartyDomain.Assign(firstPartyDomain);
return true;
}
diff --git a/caps/tests/gtest/TestOriginAttributes.cpp b/caps/tests/gtest/TestOriginAttributes.cpp
index 582de8c1c9d3..e86c5248689d 100644
--- a/caps/tests/gtest/TestOriginAttributes.cpp
+++ b/caps/tests/gtest/TestOriginAttributes.cpp
@@ -26,6 +26,8 @@ static void TestFPD(const nsAString& spec, const nsAString& fpd) {
ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
attrs.SetFirstPartyDomain(true, url);
EXPECT_TRUE(attrs.mFirstPartyDomain.Equals(fpd));
+
+ TestSuffix(attrs);
}
TEST(OriginAttributes, Suffix_default)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits