Bug #72071 [NEW]: setcookie allows max-age to be negative

From: Date: Thu, 21 Apr 2016 21:41:12 +0000
Subject: Bug #72071 [NEW]: setcookie allows max-age to be negative
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200682@lists.php.net to get a copy of this message
From:             bfrance
Operating system: Linux
PHP version:      5.6.20
Package:          *General Issues
Bug Type:         Bug
Bug description:setcookie allows max-age to be negative

Description:
------------
I believe 7.x has the same issues, but I am using 5.6.x.

setcookie is setting a negative max-age value.  The RFC:

https://tools.ietf.org/html/rfc7234#section-5.2.2.8

states max-age is delta-seconds, which is defined in RFC:

https://tools.ietf.org/html/rfc7234#section-1.2.1

"The delta-seconds rule specifies a non-negative integer, representing
time in seconds."

The test script below shows that the max age is getting set to negative
values instead of zero.


In fixing this bug I noticed that it was also doing a time(NULL) instead
of calling sapi_get_request_time().  I fixed that as well.


Test script:
---------------
<?php
setcookie("TestCookie-Now-3600", "1", time() - 3600);
setcookie("TestCookie-Now+3600", "1", time() + 3600);
?>

Expected result:
----------------
Set-Cookie: TestCookie-Now-3600=1; expires=Thu, 21-Apr-2016 19:29:15
GMT; Max-Age=0
Set-Cookie: TestCookie-Now+3600=1; expires=Thu, 21-Apr-2016 21:29:15
GMT; Max-Age=3600

Actual result:
--------------
Set-Cookie: TestCookie-Now-3600=1; expires=Thu, 21-Apr-2016 19:29:09
GMT; Max-Age=-3600
Set-Cookie: TestCookie-Now+3600=1; expires=Thu, 21-Apr-2016 21:29:09
GMT; Max-Age=3600

-- 
Edit bug report at https://bugs.php.net/bug.php?id=72071&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=72071&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=72071&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=72071&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=72071&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=72071&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=72071&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=72071&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=72071&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=72071&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=72071&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=72071&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=72071&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=72071&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72071&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=72071&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=72071&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=72071&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72071&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=72071&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=72071&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#200682) next »