Return-Path: Delivered-To: apmail-perl-modperl-archive@www.apache.org Received: (qmail 43291 invoked from network); 18 Sep 2009 16:17:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Sep 2009 16:17:06 -0000 Received: (qmail 2208 invoked by uid 500); 18 Sep 2009 16:17:05 -0000 Delivered-To: apmail-perl-modperl-archive@perl.apache.org Received: (qmail 2181 invoked by uid 500); 18 Sep 2009 16:17:05 -0000 Mailing-List: contact modperl-help@perl.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list modperl@perl.apache.org Received: (qmail 2173 invoked by uid 99); 18 Sep 2009 16:17:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2009 16:17:04 +0000 X-ASF-Spam-Status: No, hits=-16.3 required=10.0 tests=ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED,SPF_PASS,TRACKER_ID,USER_IN_DEF_SPF_WL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of dihnen@amazon.com designates 207.171.184.25 as permitted sender) Received: from [207.171.184.25] (HELO smtp-fw-9101.amazon.com) (207.171.184.25) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Sep 2009 16:16:57 +0000 X-IronPort-AV: E=Sophos;i="4.44,410,1249257600"; d="scan'208";a="270228694" Received: from smtp-in-1105.vdc.amazon.com ([10.140.9.24]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 18 Sep 2009 16:16:35 +0000 Received: from ex-hub-4101.ant.amazon.com (ex-hub-4101.ant.amazon.com [10.248.163.22]) by smtp-in-1105.vdc.amazon.com (8.12.11/8.12.11) with ESMTP id n8IGGY6V013262 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=FAIL) for ; Fri, 18 Sep 2009 16:16:35 GMT Received: from EX-SEA5-D.ant.amazon.com ([10.248.163.29]) by ex-hub-4101.ant.amazon.com ([10.248.163.22]) with mapi; Fri, 18 Sep 2009 09:16:34 -0700 From: "Ihnen, David" To: mod_perl list Date: Fri, 18 Sep 2009 09:16:33 -0700 Subject: RE: Ways to scale a mod_perl site Thread-Topic: Ways to scale a mod_perl site Thread-Index: Aco4R7OSFSn0r9oER7Wc4FFAkKXN+gAMRoPw Message-ID: References: <4AB10CB8.7010202@plusthree.com> <4AB10EA2.70108@gmail.com> In-Reply-To: <4AB10EA2.70108@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org It amounts to shared private key security. Each web server, for instance, is configured with the key abcd1234 The session looks like=20 { username =3D> 'dog' , group =3D> 'canid' , premium =3D> 0 , login_time =3D> 1253289574 } I serialize that into a string with join '|', (map { $_, $session->{$_} } s= ort keys %session; $cookiebase =3D login_time|1253289574|group|canid|premium|0|username|dog I apply md5_hex from the Digest::MD5 module $signature =3D md5_hex($cookiebase . "|" . 'abcd1234'); Which yields 68b07c585c18282ea418937266b031d7=20 I then construct my cookie. $cookie =3D join ':', %session, $signature; So the cookie string looks like premium:0:time:1253289574:username:dog:group:canid:68b07c585c18282ea4189372= 66b031d7 When I receive the cookie on a request I just do the inverse. my (%cookie, $signature) =3D split /:/, $cookie; die 'BOGUS SESSION' unless ($signature eq md5_hex(join '|', (map { $_, $ses= sion->{$_} } sort keys %cookie), 'abcd1234'; If you change the 'plaintext' string in any way - the md5_hex will change. = If you change or drop the signature, the md5_hex will change.=20 Its security through obscurity admittedly - security in that you can't see = my code, methodology, or shared secret configuration. But most people consider that plenty secure for securing the session data. David -----Original Message----- From: Brad Van Sickle [mailto:bvansickle3@gmail.com]=20 Sent: Wednesday, September 16, 2009 9:13 AM To: Michael Peters Cc: Mod_Perl Subject: Re: Ways to scale a mod_perl site > >> 3) Being enabled by item 2, add more webservers and balancers >> 4) Create a separate database for cookie data (Apache::Session objects) >> ??? -- not sure if good idea -- > > I've never seen the need to do that. In fact, I would suggest you drop=20 > sessions altogether if you can. If you need any per-session=20 > information then put it in a cookie. If you need this information to=20 > be tamper-proof then you can create a hash of the cookie's data that=20 > you store as part of the cookie. If you can reduce the # of times that=20 > each request needs to actually hit the database you'll have big wins. > > Can I get you to explain this a little more? I don't see how this could=20 be used for truly secure sites because I don't quite understand how=20 storing a hash in a plain text cookie would be secure.=20 The thing I hate most about my "secure" applications is the fact that I=20 have to read the DB at the start of every request to ensure that the=20 session cookie is valid and to extract information about the user from=20 the session table using the session ID stored in the cookie. Hitting=20 the DB is the quickest way to kill performance and scalability in my=20 experience. I know a lot of true app servers (Websphere, etc..) =20 store this data in cached memory, but I was unaware that there might be=20 an option for doing this without using a DB with mod_perl .