pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
securing PHP/Postgresql (was: MD5 in pg and php)
2+ messages / 2 participants
[nested] [flat]

* securing PHP/Postgresql (was: MD5 in pg and php)
@ 2004-04-29 16:57 Joolz <joolz@xs4all.nl>
  2004-05-01 12:07 ` Re: securing PHP/Postgresql (was: MD5 in pg and php) Andrew McMillan <andrew@catalyst.net.nz>
  0 siblings, 1 reply; 2+ messages in thread

From: Joolz @ 2004-04-29 16:57 UTC (permalink / raw)
  To: pgsql-php

> [Bruno Wolff III schreef op 29-04-2004 05:11 -0500]
>
> On Thu, Apr 29, 2004 at 09:07:16 +0200,
>   Joolz <joolz@xs4all.nl> wrote:
> > 
> > I want to store passwords in a pg db, MD5 seems like a good way to
> > enhance security (no more plaintext passwords over the line etc.)
> > I had a look at MD5, in PHP 4.3.4 there is a function md5() which
> > seems to work nicely:
> 
> This may not help as much as you think. If you are using an ssl
> connection, the passwords won't be sent in the clear. If you aren't
> using an ssl connection the hashes will be in clear. I don't believe
> the postgres uses a random challenge so that you won't really raise
> the bar much.  Plus if snooping passwords is a threat, most likely
> snooping data will be as well (though not always) and forcing
> connections to use ssl may be your best bet. I believe as typically
> used this is vulnerable to man in the middle attacks, but these are
> going to be significantly harder to do than simple snooping.

Thanks for the tip. I already have things like:

  if (ini_get('register_globals') === 1) {
    say it's not safe, don't enter the application }

and

  if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
    idem }

in my login screen. Still, I would feel more assured if passwords go
over the line md5()'d, even if that line is encrypted.

I have other things to worry about next. Right now I let the user
enter the pg username and password, store these values in session
variables and use them every time a database connection is needed.

Someone told me this is very insecure, as the session variables are
stored in either /tmp on the server (that's where I have them put), in
a local cookie or in the URL. Neither would be safe, a better approach
would be to authenticicate once (by looking up the user + password in
a table), and give access to certain tables, views etc. based on the
result of the first lookup; the result being different roles in the
organisation who have access to certain views etc. or a simple 'false'
if the password is wrong.

I have to think about it long and hard :-), the extra "layer" makes
things more secure, I would only have to register username (for
auditing purposes) plus the "role" in session variables, which could
be md5()'d. Still, the extra layer is from a logical point of view
redundant and thus errorprone.

Still, it might be a good idea. If anyone cares to share their opinion
on the matter (or discuss how you handled this), TIA!

-- 
18:38-18:57
Fedora Core release 1 (Yarrow) Linux 2.4.22-1.2188.nptl



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: securing PHP/Postgresql (was: MD5 in pg and php)
  2004-04-29 16:57 securing PHP/Postgresql (was: MD5 in pg and php) Joolz <joolz@xs4all.nl>
@ 2004-05-01 12:07 ` Andrew McMillan <andrew@catalyst.net.nz>
  0 siblings, 0 replies; 2+ messages in thread

From: Andrew McMillan @ 2004-05-01 12:07 UTC (permalink / raw)
  To: pgsql-php

On Thu, 2004-04-29 at 18:57 +0200, Joolz wrote:
> 
> I have to think about it long and hard :-), the extra "layer" makes
> things more secure, I would only have to register username (for
> auditing purposes) plus the "role" in session variables, which could
> be md5()'d. Still, the extra layer is from a logical point of view
> redundant and thus errorprone.
> 
> Still, it might be a good idea. If anyone cares to share their opinion
> on the matter (or discuss how you handled this), TIA!

For myself, I handle security roughly as follows:

Password is stored as a salted md5, which means that two users with the
same password have different on-disk records of it.

Logged in user gets a session cookie which is an md5 of random data plus
a session id.  The session id is looked up, and the random data (which
is only known server-side) is validated.  Of course the session id is
predictable, but the random data is not.

I use a general user-id to access the database, rather than database
users and permissions.  I generally find that the database permissions
model is not a good fit to the permissions I want for my website.

Hope this is of interest,
					Andrew McMillan.
-------------------------------------------------------------------------
Andrew @ Catalyst .Net .NZ  Ltd,  PO Box 11-053,  Manners St,  Wellington
WEB: http://catalyst.net.nz/             PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201       MOB: +64(21)635-694      OFFICE: +64(4)499-2267
                        
-------------------------------------------------------------------------




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2004-05-01 12:07 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-04-29 16:57 securing PHP/Postgresql (was: MD5 in pg and php) Joolz <joolz@xs4all.nl>
2004-05-01 12:07 ` Andrew McMillan <andrew@catalyst.net.nz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox