r93459 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93458‎ | r93459 | r93460 >
Date:13:51, 29 July 2011
Author:daniel
Status:deferred (Comments)
Tags:
Comment:
Allow fixed session ids for users authenticated via IP.

This allows sessions to be used even if the client does not send a session cookie,
as is often the case with command line scripts using wget or some such to poll the wiki.
Modified paths:
  • /trunk/extensions/IPAuth/IPAuth.php (modified) (history)

Diff [purge]

Index: trunk/extensions/IPAuth/IPAuth.php
@@ -50,8 +50,37 @@
5151 $wgIPAuthUsers = array( );
5252 # $wgIPAuthUsers = array( "127.0.0.1" => "LocalUser" );
5353
 54+$wgIPAuthIdSecret = null;
 55+
 56+$wgHooks['UserLoadFromSession'][] = 'ipAuthUserLoadFromSession';
5457 $wgHooks['UserLoadAfterLoadFromSession'][] = 'ipAuthUserLoadAfterLoadFromSession';
5558
 59+function ipAuthUserLoadFromSession( $user, &$result ) {
 60+ global $wgIPAuthUsers, $wgRequest, $wgIPAuthIdSecret;
 61+
 62+ if ( !$wgIPAuthIdSecret ) {
 63+ return true;
 64+ }
 65+
 66+ $ip = wfGetIP();
 67+ if ( isset( $wgIPAuthUsers[ $ip ] ) ) {
 68+ $name = $wgIPAuthUsers[ $ip ];
 69+
 70+ if ( !$wgRequest->checkSessionCookie() ) { // if the client didn't provide a session cookie
 71+ // pick a new session id to avoid setting up a fresh session over and over.
 72+ // NOTE: <http://www.php.net/manual/en/function.session-id.php> sais:
 73+ // Depending on the session handler, not all characters are allowed within the session id.
 74+ // For example, the file session handler only allows characters in the range a-z A-Z 0-9 , (comma) and - (minus)!
 75+ $sid = "ipauth" . '-' . preg_replace('![_.:]!', '-', $ip) . '-' . md5("$name:$ip:$wgIPAuthIdSecret");
 76+
 77+ wfDebug( "Forcing session id for $name at $ip to $sid\n" );
 78+ session_id($sid); //note: hope session isn't already open.
 79+ }
 80+ }
 81+
 82+ return true;
 83+}
 84+
5685 function ipAuthUserLoadAfterLoadFromSession( $user ) {
5786 global $wgIPAuthUsers;
5887
@@ -87,4 +116,3 @@
88117
89118 return true;
90119 }
91 -

Comments

#Comment by Nikerabbit (talk | contribs)   16:42, 29 July 2011

s/sais/says/ :o

Status & tagging log