Commit graph

59 commits

Author SHA1 Message Date
Brad Jorsch
8885b548ad WebReponse: Use values altered in 'WebResponseSetCookie' hook
The 'WebResponseSetCookie' hook is allowed to alter the data for the
cookie being set. We need to actually use those altered values, rather
than setting $cookie and $data earlier in the function.

Bug: T198525
Change-Id: Ia817e3dc5ce17fdcf5057ee5fcb6980baa1333d6
2018-07-09 11:01:05 -04:00
jenkins-bot
eb0758923d Merge "Disable WebResponse setters for post-send processing" 2018-06-13 13:21:51 +00:00
Fomafix
0f1858321c Use PHP 7 '??' operator instead of if-then-else
Change-Id: I790b86e2e9e3e41386144637659516a4bfca1cfe
2018-06-12 23:14:18 +02:00
Brad Jorsch
23706be35c Disable WebResponse setters for post-send processing
When jobs are being run synchronously post-send, we don't want to allow
bugs to result in a job somehow setting cookies or headers that
interfere with those that were intended to be set in the request.

Bug: T191537
Change-Id: Ib5714a17af417797140f99e41eaacbba1bfd20f4
2018-06-12 12:35:41 -04:00
Tim Starling
f193271cff Log a backtrace from the culprit location if headers were already sent
Install the backtrace collector very early, so that we can get the
backtrace even if headers were sent from LocalSettings.php.

Bug: T157392
Change-Id: I9bc732b34481c95afb5362e135a87bd4302498e2
2017-02-23 14:10:12 +11:00
Chad Horohoe
c78d1c842f Log a warning when headers were already sent and we can't
Change-Id: Id01f4712e3dd297594e9ed2389ad411be5f553e7
2017-02-08 13:38:58 -08:00
Alexander I. Mashin
0c34f5fc1a Fix to incorrect calls of header () breaking saving some pages and login
This is to fix incorrect calls of header () with null as its third parametre
in WebResponse::header ().

Under HHVM 3.14.3 this causes warnings in error.log and breaks saving page
and user login.

Bug: T140864
Change-Id: I98291e2746e92e22672de077bccfb36ae91d2c62
2016-09-21 20:20:33 +00:00
Reedy
6ad0357839 Remove old WebResponse::setCookie() calling method
Change-Id: Ibd548ea5bfe08f7fef35273c5a9c6c70c3faf60e
2016-06-04 15:14:40 +00:00
Bryan Davis
8b413431d7 Guard against allowing intermediate caching when cookies are present
Output cache-control headers that disable intermediate caching even if
OutputPage->mEnableClientCache is true when the response includes
set-cookie headers as well. This change mirrors logic that has been in
use on the Wikimedia Foundation production cluster's Varnish cache
system for over 2 years to guard against accidentally caching backend
responses which include Set-Cookie headers.

Co-Author: Max Semenik <maxsem.wiki@gmail.com>
Bug: T127993
Change-Id: I1a0d38a5b9dba754b91a7832371b3dc0df51bd5a
2016-02-29 15:29:58 -07:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Bryan Davis
cfbc25c5a5 Allow changing cookie options in WebResponseSetCookie hook
Pass the cookie options by value to WebResponseSetCookie handlers so
that they may alter them.

Bug: T49647
Change-Id: I69ae55baa7806f14726b0b08215c0df471794b39
2016-02-10 15:49:08 -07:00
Bryan Davis
31d4359b45 Fix typo in cookie key
Fix typo in cookie key name introduced in I1098d05

Bug: T124641
Change-Id: Ib140aa61ba56844191304c4308052148c728bc64
2016-01-25 09:02:59 -07:00
Brad Jorsch
4d6d06253b Move avoidance of setting deleted cookies into WebResponse
There's no reason this should be only in CookieSessionProvider when
we're already handling deduplication in WebResponse.

Further, this fixes the bug in the existing CookieSessionProvider
implementation that a setCookie() followed by a clearCookie() wouldn't
actually clear the cookie.

This reverts commit 1ce684fcef.

Bug: T124252
Change-Id: I1098d054facacd59f03ebed7c747ec9ff6bf66e7
Depends-On: I61d14bf80fa7c857dec9cffb366dc3f84dbb4faf
2016-01-25 03:34:11 +00:00
Brad Jorsch
a73c5b7395 Add SessionManager
SessionManager is a general-purpose session management framework, rather
than the cookie-based sessions that PHP wants to provide us.

While fallback is provided for using $_SESSION and other PHP session
management functions, they should be avoided in favor of using
SessionManager directly.

For proof-of-concept extensions, see OAuth change Ib40b221 and
CentralAuth change I27ccabdb.

Bug: T111296
Change-Id: Ic1ffea74f3ccc8f93c8a23b795ecab6f06abca72
2016-01-12 21:57:01 +00:00
Gergő Tisza
eaf5dabf88 Add WebResponse::clearCookie()
Easier-to-read alias for setCookie(..., '', time() - 86400).

Change-Id: I0357c4a38085c4754bf6ff7e40756179d19b912d
2015-11-03 20:14:33 +00:00
Brad Jorsch
c3dc398514 FauxResponse: Honor cookie options, and other cleanup
We have this nice class for unit testing cookie-setting, but the
cookie-setting method ignores all the parameters! Fix that. Also provide
accessors to check the entire set of cookie data, and the set cookies as
a whole.

While this does change the semantics of FauxRequest::getcookie() in that
the name now needs to be prefixed, no extension in Gerrit uses this
method so we should be fine.

Also clean up the case of the setCookie and getCookie methods while
we're at it. Since PHP method names are case-insensitive, this doesn't
even break compatibility with extensions.

Change-Id: Ib44a074bf9796bc0b470d557e39465792f399d30
2015-09-29 22:45:56 +00:00
Timo Tijhof
f57b6af45b WebResponse: Implement statusHeader() using the new HttpStatus::header()
* Convert existing use of WebResponse::header() for HTTP status headers
  to use this new statusHeader() method.

* Extend unit test forFauxResponse.

I'm not calling HttpStatus::header directly in code. We keep the abstraction
layer of WebResponse so that responses can continue to be mocked/fauxed without
affecting the outer HTTP response.

Change-Id: I8a536e16659fa88b54cffa1457efb889efa5fcd6
2015-06-04 02:27:30 +00:00
Thiemo Mättig
53e6c5b237 Set parameter default to array() in WebResponse::setcookie()
This is a direct follow-up for the question raised in Ifab16c2.
Null is not a meaningful value in this case. As far as I can see the
only reason it was added was to make the parameter optional. Optional
array parameters are better marked with "= array()".

Change-Id: I86965d390fdb718de7fb81a9f4c48b2261c16aa9
2015-03-27 09:58:58 +01:00
Thiemo Mättig
63a8237c64 Fix inline documentation in WebResponse
Main reason to touch this file are the missing "null" types in the
documentation.

Change-Id: Ifab16c276efb3d8c4aa0a27d8d5106d4e3303794
2015-03-26 18:48:47 +00:00
Aaron Schulz
e369f66d00 Replace wfRunHooks calls with direct Hooks::run calls
* This avoids the overhead of an extra function call

Change-Id: I8ee996f237fd111873ab51965bded3d91e61e4dd
2014-12-10 12:26:59 -08:00
Ori Livneh
67e9b8e394 Add WebResponse::getHeader()
Equivalent to FauxResponse::getHeader()
Also change case of FauxResponse::getHeader.

Change-Id: I569b2ebbcd166f5d0a5a5f2dfa913a6aa49e13f4
2014-11-07 11:19:12 -08:00
umherirrender
a203032d00 Docs: compatability -> compatibility
https://en.wiktionary.org/wiki/compatability

Change-Id: I71d82ae04d4b17609a1d5a7eec4497115e64972e
2014-08-13 19:39:07 +02:00
umherirrender
1c68a1ee86 Cleanup some docs (includes/*.php)
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: I783e4dbfe5f6f98b32b9a03ccf6439e13e132bcc
2014-07-24 19:42:24 +02:00
umherirrender
829886b10a Fixed some @params documentation
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.

Change-Id: I64e8cfe478cb0ba438f40b0631d6e9049cdab567
2014-04-14 12:59:19 +00:00
Kevin Israel
00b7f76aaf Remove $wgHttpOnlyBlacklist
This hack was added in r34083 / 6b16f44108 to support IE for Mac.
That browser is no longer supported, and no additional user-agent
strings have been added in WMF configuration.

Change-Id: Iffba121a9964e2ad387fad8827ddfd8dabcbd12e
2014-03-20 21:19:08 -04:00
Brad Jorsch
54bf87d346 Improve WebResponse::setcookie
Various bits of code are not using this because it doesn't support
various use cases, e.g. session cookies, httpOnly, custom paths, etc.

Refactor it to add all those options. Also add a hook so extensions can
override the setting of the cookie.

Change-Id: Ia0c424a48d9455a8574d91631cde0f00c9882288
2013-08-07 17:43:06 -04:00
Tyler Anthony Romeo
c2c40b2b9b Fixed $wgCookieExpiration functionality when set to 0.
When $wgCookieExpiration is set to 0, cookies should
by default expire when the browser closes. However,
MediaWiki accidentally interpreted this as the cookies
expiring 0 seconds from the request time.

Bug: 47886
Change-Id: Ib988ad18574122a56b0d11c8888c7c41d94dea6e
2013-07-03 17:35:02 +00:00
daniel
1da2dd7983 Make headers in FauxRequest case insensitive
HTTP headers are case insensitive per spec, and WebRequest
treats them like that, so FauxRequest should too.

Change-Id: I4257af7a8de2792ac556c670dcc7f28e4af4cb44
2013-06-03 16:23:11 +02:00
umherirrender
ef2f507d23 Fixed spacing in files direct in includes folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: Ibb8dd102db045522d12ff939075ba7420d95ab6b
2013-04-21 06:38:49 +00:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
Ori Livneh
8debd7b5cd Flip order of conditionals and add explanatory note
The conditional is nominally more performant and considerably more readable
with its constituents flipped. Also adds an explanatory note. Prompted by
confusion over change Ie89507f8e98c365df9d93a7633223103b9025790.

Change-Id: I2d3db63bdbcebe0fd59c063c9f371362c9d07f91
2013-02-25 22:02:14 +00:00
Matthew Flaschen
3f4e273a7b Fix documentation error for $expire in WebResponse::setcookie.
Change-Id: I657ba9b722706d3c71a6fffa3f4b94d35d8de7c5
2013-02-23 08:07:43 +01:00
umherirrender
1044b0b8df fix some spacing
Change-Id: I8f976013f33c5818e4402604fe8610aa3f43b0c6
2013-02-04 20:18:33 +00:00
umherirrender
6fbbbd17ca fix some spacing
Change-Id: Ie7bb35871cc99237f3a655f7db22ca1f0646df5e
2013-01-27 14:21:50 +01:00
Antoine Musso
9362bb6c56 miscellaneous doxygen warnings
* @licence -> @license
* Protects inline HTML by using double quotes, our inline comments uses
  elements such as <h1> or <firstnameLastname@gmail.com>
* Commands in lowercase (@TODO -> @todo, @NOTE -> @note)
* removes @abstract and @static since doxygen detects them from PHP
  code.
* various undocumented function parameters
* typos in parameters declarations

Change-Id: I62ad6fc124c355bf31acc780b9614a59cf79a421
2012-10-22 14:00:08 +02:00
csteipp
5801da5f86 (bug 29898) Set cookie to force HTTPS from HTTP
Sets a cookie on user login (removed on logout) if wpStickHTTPS
was checked, which causes the browser to get a redirect if they
visit the HTTP version of the site.

Change-Id: I60f44a1062a93d15198edae6674bb3310a148b2d
2012-09-21 15:47:59 -07:00
Antoine Musso
fc6bc233be Fix doxygen docs before REL1_19 branching 2012-02-01 20:53:38 +00:00
Sam Reed
6d466491c6 Followup r94211
Bug 30315 - Declaration of FauxResponse::setcookie() should be compatible with that of WebResponse::setcookie()
2011-08-11 00:17:58 +00:00
Chad Horohoe
052f542165 Allow overriding $wgCookiePrefix and $wgCookieDomain in WebResponse::setcookie() so I can stop crying when I look at things like CentralAuth and CentralNotice 2011-08-10 23:27:10 +00:00
Alexandre Emsenhuber
0511b15706 * Added some tests for FauxResponse class
* Made some fixes to that class and removed one unused variable
2011-07-13 20:16:14 +00:00
Alexandre Emsenhuber
303eb51924 Per Brion, fix for r91460: make this a bit more robust 2011-07-05 16:40:12 +00:00
Alexandre Emsenhuber
2f7f99b1f1 * Don't create a WebRequest obhject in CLI mode but a FauxRequest; avoids some useless notices about headers already sent (I know this is more a PHP silliness, but anyway)
* Added HTTP response code parsing (sending a "HTTP/1.x code" header was throwing a NOTICE about undefined index on the result of the explode() call) and storage; added FauxResponse::getStatusCode() to retrieve it
2011-07-05 15:05:14 +00:00
Alexandre Emsenhuber
e7eaf43077 Added some GPL headers 2011-06-28 18:21:59 +00:00
Sam Reed
d3cd73cc25 Documentation updates and additions 2011-06-05 21:04:48 +00:00
Sam Reed
29d159aeba * (bug 22179) Internal use of API (FauxRequest) results in HTTP headers being set
Per Chad, switch API to use WebResponse::header() wrapper

Add $http_response_code to WebResponse::header()


Fix some code spacing/whitespace issues
2011-06-05 19:51:31 +00:00
Alexandre Emsenhuber
bc8abfe5b1 Drop 5.1 compatibility calls to session_set_cookie_params() and setcookie() since we require 5.2.3+ now 2011-04-01 09:50:09 +00:00
Alexandre Emsenhuber
7b79d94515 * Standardised file description headers
* Added some descriptions
* Added @file where needed
2010-08-14 17:42:40 +00:00
Mark A. Hershberger
c74fe71cd8 * new FauxResponse class to help with unit testing
* Add append() method to FileRepo classes to enable chunked uploading
* Change chunksessionkey to chunksession
* Remove echo json stuff
* Fix a multitude of bugs in my own code
* still to test: mwEmbed use of chunked upload
2010-02-10 10:36:11 +00:00
Aaron Schulz
c155fd4e4a Revert r43804 'This should probably be in Response, not Request, as we're setting data, not getting it. Nothing's using it yet (fairly new), so nothing to update.'
Session id is used by client request to specify its login data from cookie, so the session data, by extensions, is like a sort of request parameter. Also, WebResponse.php seems to be used for data actually sent to the client, like requested cookies.
2008-11-21 09:55:13 +00:00
Chad Horohoe
bf244b740f This should probably be in Response, not Request, as we're setting data, not getting it. Nothing's using it yet (fairly new), so nothing to update. 2008-11-21 09:01:26 +00:00