Verified Commit d13f55b7 authored by valenting's avatar valenting Committed by ma1
Browse files

Bug 2040905 - nsStandardURL::Deserialize should reparse the URL a=diannaS DONTBUILD

parent 7448316b
Loading
Loading
Loading
Loading
+24 −1
Changes for dom/security/test/unit/test_csp_deserialization.js: 24 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -45,9 +45,32 @@ add_task(function () {
    )
  );

  // The pref is read while deserializing, so each case has to re-read the blob
  // after setting it.
  const REPARSE_PREF = "network.ipc.reparse_deserialized_uri";
  registerCleanupFunction(() => Services.prefs.clearUserPref(REPARSE_PREF));

  Services.prefs.setBoolPref(REPARSE_PREF, false);
  Assert.equal(
    E10SUtils.serializeCSP(v136),
    E10SUtils.serializeCSP(E10SUtils.deserializeCSP(DATA_v136)),
    DATA_v136,
    "DANGER: serialization format might have changed!"
  );

  // nsStandardURL::Deserialize re-parses the spec when this pref is set, which
  // recomputes every segment. An absent segment has no text to point at, so a
  // re-parse leaves it where it would start rather than where the stored blob
  // put it, and the bytes differ even though the CSP and the URL do not.
  //
  // DATA_v136 with the offsets a re-parse of "https://example.org/" gives the
  // absent username (8), password (8), extension (20), query (19) and ref (19)
  // segments, in place of the zeroes Firefox 136 wrote.
  const DATA_v136_REPARSED =
    "CdntGuXUQAS/4CfOuSPZrAAAAAAAAAAAwAAAAAAAAEYB3pRy0IA0EdOTmQAQS6D9QJIHOlRteE8wkTq4cYEyCMYAAAAC/////wAAAbsBAAAAFGh0dHBzOi8vZXhhbXBsZS5vcmcvAAAAAAAAAAUAAAAIAAAACwAAAAj/////AAAACP////8AAAAIAAAACwAAABMAAAABAAAAEwAAAAEAAAATAAAAAQAAABQAAAAAAAAAFP////8AAAAA/////wAAABP/////AAAAE/////8BAAAAAAAAAAAAInsiMSI6eyIwIjoiaHR0cHM6Ly9leGFtcGxlLm9yZy8ifX0AAAACAAAAEgBkAGUAZgBhAHUAbAB0AC0AcwByAGMAIAAnAHMAZQBsAGYAJwABAAAAAA4AaQBtAGcALQBzAHIAYwAgACcAbgBvAG4AZQAnAAEA";
  Services.prefs.setBoolPref(REPARSE_PREF, true);
  Assert.equal(
    E10SUtils.serializeCSP(E10SUtils.deserializeCSP(DATA_v136)),
    DATA_v136_REPARSED,
    "DANGER: serialization format might have changed!"
  );
});
+7 −0
Changes for modules/libpref/init/StaticPrefList.yaml: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -14438,6 +14438,13 @@
  value: 1048576
  mirror: always
# Whether nsStandardURL::Deserialize should reparse the URL
# it got from the content process
- name: network.ipc.reparse_deserialized_uri
  type: RelaxedAtomicBool
  value: true
  mirror: always
# If true, use the HSTS preload list.
- name: network.stricttransportsecurity.preloadlist
  type: RelaxedAtomicBool
+16 −1
Changes for netwerk/base/nsStandardURL.cpp: 16 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -1075,7 +1075,6 @@ nsresult nsStandardURL::ReadSegment(nsIBinaryInputStream* stream,
nsresult nsStandardURL::WriteSegment(nsIBinaryOutputStream* stream,
                                     const URLSegment& seg) {
  nsresult rv;

  rv = stream->Write32(seg.mPos);
  if (NS_FAILED(rv)) {
    return rv;
@@ -3451,6 +3450,15 @@ nsresult nsStandardURL::ReadPrivate(nsIObjectInputStream* stream) {

  NS_ENSURE_TRUE(CheckSegmentInvariants(), NS_ERROR_MALFORMED_URI);

  if (StaticPrefs::network_ipc_reparse_deserialized_uri() &&
      XRE_IsParentProcess()) {
    nsAutoCString spec(mSpec);
    rv = SetSpecInternal(spec);
    if (NS_FAILED(rv)) {
      return rv;
    }
  }

  rv = CheckIfHostIsAscii();
  if (NS_FAILED(rv)) {
    return rv;
@@ -3753,6 +3761,13 @@ bool nsStandardURL::Deserialize(const URIParams& aParams) {
    return false;
  }

  if (StaticPrefs::network_ipc_reparse_deserialized_uri() &&
      XRE_IsParentProcess()) {
    if (NS_FAILED(SetSpecInternal(params.spec()))) {
      return false;
    }
  }

  nsresult rv = CheckIfHostIsAscii();
  if (NS_FAILED(rv)) {
    return false;