Skip to content

prohibit empty cookie names for setcookie() #1258

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
5 changes: 4 additions & 1 deletion ext/standard/head.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ PHPAPI int php_setcookie(char *name, size_t name_len, char *value, size_t value_
int result;
zend_string *encoded_value = NULL;

if (name && strpbrk(name, "=,; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */
if (!name_len) {
zend_error( E_WARNING, "Cookie names must not be empty" );
return FAILURE;
} else if (name && strpbrk(name, "=,; \t\r\n\013\014") != NULL) { /* man isspace for \013 and \014 */
zend_error( E_WARNING, "Cookie names cannot contain any of the following '=,; \\t\\r\\n\\013\\014'" );
return FAILURE;
}
Expand Down
8 changes: 8 additions & 0 deletions ext/standard/tests/network/bug69523.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--TEST--
setcookie() allows empty cookie name
--FILE--
<?php
setcookie('', 'foo');
?>
--EXPECTF--
Warning: Cookie names must not be empty in %s on line %d