Skip to content

Fix bug #76232: SoapClient Cookie Header Semicolon #14406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ext/soap/php_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ int make_http_soap_request(zval *this_ptr,
zval *data;
zend_string *key;
has_cookies = 1;
bool first_cookie = true;
smart_str_append_const(&soap_headers, "Cookie: ");
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(cookies), key, data) {
if (key && Z_TYPE_P(data) == IS_ARRAY) {
Expand All @@ -848,10 +849,13 @@ int make_http_soap_request(zval *this_ptr,
Z_TYPE_P(tmp) != IS_STRING ||
in_domain(ZSTR_VAL(phpurl->host),Z_STRVAL_P(tmp))) &&
(use_ssl || (tmp = zend_hash_index_find(Z_ARRVAL_P(data), 3)) == NULL)) {
if (!first_cookie) {
smart_str_appends(&soap_headers, "; ");
}
first_cookie = false;
smart_str_append(&soap_headers, key);
smart_str_appendc(&soap_headers, '=');
smart_str_append(&soap_headers, Z_STR_P(value));
smart_str_appendc(&soap_headers, ';');
}
}
}
Expand Down
67 changes: 67 additions & 0 deletions ext/soap/tests/bugs/bug76232.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--TEST--
Bug #76232 (SoapClient Cookie Header Semicolon)
--EXTENSIONS--
soap
--SKIPIF--
<?php
if (!file_exists(__DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc")) {
echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
}
?>
--FILE--
<?php

include __DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc";

$args = ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=" . (substr(PHP_OS, 0, 3) == "WIN" ? "php_" : "") . "soap." . PHP_SHLIB_SUFFIX];
if (php_ini_loaded_file()) {
// Necessary such that it works from a development directory in which case extension_dir might not be the real extension dir
$args[] = "-c";
$args[] = php_ini_loaded_file();
}
$code = <<<'PHP'
/* Receive */
$content = trim(file_get_contents("php://input")) . PHP_EOL;
PHP;

php_cli_server_start($code, null, $args);

$client = new soapclient(NULL, [
'location' => 'http://' . PHP_CLI_SERVER_ADDRESS,
'uri' => 'misc-uri',
'trace' => true,
]);

echo "=== Request with one cookie ===\n";

$client->__setCookie('testcookie1', 'true');
$client->__soapCall("foo", []);
echo $client->__getLastRequestHeaders();

echo "=== Request with two cookies ===\n";

$client->__setCookie('testcookie2', 'true');
$client->__soapCall("foo", []);

echo $client->__getLastRequestHeaders();
?>
--EXPECTF--
=== Request with one cookie ===
POST / HTTP/1.1
Host: %s
Connection: Keep-Alive
User-Agent: PHP-SOAP/%s
Content-Type: text/xml; charset=utf-8
SOAPAction: "misc-uri#foo"
Content-Length: %d
Cookie: testcookie1=true

=== Request with two cookies ===
POST / HTTP/1.1
Host: %s
Connection: Keep-Alive
User-Agent: PHP-SOAP/%s
Content-Type: text/xml; charset=utf-8
SOAPAction: "misc-uri#foo"
Content-Length: %d
Cookie: testcookie1=true; testcookie2=true
Loading