diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index 9e1ecb8..7b9302a 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -176,6 +176,13 @@
   protected $kernel;
 
   /**
+   * Cookies to set on curl requests.
+   *
+   * @var array
+   */
+  protected $curlCookies = array();
+
+  /**
    * Constructor for \Drupal\simpletest\WebTestBase.
    */
   function __construct($test_id = NULL) {
@@ -971,8 +978,10 @@ protected function tearDown() {
     $this->loggedInUser = FALSE;
     $this->additionalCurlOptions = array();
 
-    // Close the CURL handler.
+    // Close the CURL handler and reset the cookies array used for upgrade
+    // testing so test classes containing multiple tests are not polluted.
     $this->curlClose();
+    $this->curlCookies = array();
   }
 
   /**
@@ -1070,6 +1079,10 @@ protected function curlExec($curl_options, $redirect = FALSE) {
       $curl_options[CURLOPT_HTTPHEADER][] = 'Expect:';
     }
 
+    $cookies = array();
+    if (!empty($this->curlCookies)) {
+      $cookies = $this->curlCookies;
+    }
     // In order to debug webtests you need to either set a cookie or have the
     // xdebug session in the URL. If the developer listens to connection on the
     // parent site, by default the cookie is not forwarded to the client side,
@@ -1077,6 +1090,11 @@ protected function curlExec($curl_options, $redirect = FALSE) {
     // this bit of information is forwarded. Make sure that the debugger listens
     // to at least three external connections.
     if (isset($_COOKIE['XDEBUG_SESSION'])) {
+      $cookies[] = 'XDEBUG_SESSION=' . $_COOKIE['XDEBUG_SESSION'];
+    }
+
+    // Merge additional cookies in.
+    if (!empty($cookies)) {
       $curl_options += array(
         CURLOPT_COOKIE => '',
       );
@@ -1084,7 +1102,7 @@ protected function curlExec($curl_options, $redirect = FALSE) {
       if (!empty($curl_options[CURLOPT_COOKIE])) {
         $curl_options[CURLOPT_COOKIE] = rtrim($curl_options[CURLOPT_COOKIE], '; ') . '; ';
       }
-      $curl_options[CURLOPT_COOKIE] .= 'XDEBUG_SESSION=' . $_COOKIE['XDEBUG_SESSION'] . '; ';
+      $curl_options[CURLOPT_COOKIE] .= implode('; ', $cookies) . ';';
     }
 
     curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
index d7052fa..3ff5bc6 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UpgradePathTestBase.php
@@ -61,7 +61,7 @@ protected function prepareD8Session() {
     // Generate and set a D7-compatible session cookie.
     $this->curlInitialize();
     $sid = Crypt::hashBase64(uniqid(mt_rand(), TRUE) . Crypt::randomBytes(55));
-    curl_setopt($this->curlHandle, CURLOPT_COOKIE, rawurlencode(session_name()) . '=' . rawurlencode($sid));
+    $this->curlCookies[] = rawurlencode(session_name()) . '=' . rawurlencode($sid);
 
     // Force our way into the session of the child site.
     drupal_save_session(TRUE);
