473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Authentication with sessions...

Hey all--

I'm building a database and I basically need to keep out people who
aren't authorized, but it's not like I need top security here. I'm just
doing basic user/pass of a SQL database, and when a user authenticates
I start a session for him.

My question is, is there any way for a hacker to easily start a session
without having logged in? For instance, if I save the user name and IP
address in the session will it be relatively tough to fake a session?

Sorry if this is a dumb question, I really don't know much about this
yet.

Jul 17 '05 #1
10 2111
After reading this it occurred to me that I need to clarify:

I read a few examples where the SQL database is accessed on every
protected page to re-verify the user/pass information. I was just
wondering if its safe to verify it once and then pass a flag around
that says, "yes this user has been verified."

thanks again

Jul 17 '05 #2
IP addresses shouldnt be used for identifying people. Often multiple
people use the same IP address, or one person may change IP addresses
often. If they have an old telephone modem, they will have a different
IP everytime they connect. Those old modems often disconnect randomly.
If you use IP addresses to identify people, when that person
reconnects, your site will say they are unauthorized. Sessions alone
(without IP logging) should be sufficient. If you have a really high
number of users, or need more security, you may want to increase the
length of the session ID. I think this is done in the php.ini file
somewhere. That would make it less likely that a hacker could type in
a random session ID and get in, especially if there are a lot of users.
But this should only be necessary if there a really high number of
users or you need really high security.
And verifying them once then having a session variable flag that says
they have been verified should work fine.

Jul 17 '05 #3
>I'm building a database and I basically need to keep out people who
aren't authorized, but it's not like I need top security here. I'm just
doing basic user/pass of a SQL database, and when a user authenticates
I start a session for him.
PHP typically starts a session for *ANYONE*. Sessions are also
used in user tracking with no need for logins or authentication.
If by this you mean "when a user authenticates I mark the session
as logged in", fine.
My question is, is there any way for a hacker to easily start a session
without having logged in?
PHP will typically start as session for anyone who goes to the login
page, BEFORE they log in. That session won't be marked as logged in,
though.

Is it easy to GUESS an existing session of another user? In general,
no, unless the hacker is not guessing but gets the session from the
user's computer (say, by using the user's computer to look at stored
cookies), or he uses a packet sniffer to watch the user's traffic,
or he simply uses the user's computer (while user is at lunch) to
go back to your site.
For instance, if I save the user name and IP
address in the session will it be relatively tough to fake a session?


If you check the session for being logged in on every page (e.g.
you check that $_SESSION['logged_in_user'] is set to *SOMETHING*,
which you won't do unless they logged in), and you validate that
the IP still matches, that's fairly secure, as long as you're not
protecting things like actual money, medical records, nuclear launch
codes, or SSNs. You don't need to re-check the password every time.
And if you carry the password from one page to the next in a hidden
field (so the user doesn't have to type it in on every page), that's
even LESS secure as there are more copies of it going over the net
and into the user's cache.

I recommend using a session timeout, as short as you can without
inconveniencing users, consistent with the security risk. It does
help with the "unattended computer" problem. My bank uses a timeout
of 10 minutes. "Where's George" (a site where you can track where
dollar bills in your wallet have been and where they go after you
spend them) uses 1 week by default (but who CARES if hackers or the
government can enter bills on my account or see serial numbers of
bills I've had in the past? If I was nervous about that, I wouldn't
use Where's George at all. I would prefer that nobody post death
threats on the forum in my name, but that's unlikely.)

Beware that validating the IP can cause problems: some users (AOL
users seem to be the example for this, but it's not only them) go
through load-balanced proxies, so just about every page, or piece
of a page, they come through may appear to be from a different IP.
If you reject them for that, they won't be able to use your site
usefully.

Incidentally, sometimes Apache .htaccess is a very nice fit to access
control rather than using sessions. It's nice primarily because
browsers are prepared to keep the info in memory so the user doesn't
have to enter it all the time, but it's not stored on disk. However,
..htaccess doesn't do timeouts, which is often a problem.

Gordon L. Burditt
Jul 17 '05 #4
I hate sites with really short session timeout.

Jul 17 '05 #5
>I hate sites with really short session timeout.

So what do you consider "really short"? I think 10 minutes is not
unreasonable for a BANK, where a security breach could let the
intruder empty my checking account. (Remember, the timeout gets
reset every time you load a new page.) It is, however, very
unreasonable for, say, an online newspaper, where all I can do is
read newspaper articles, and it might well take more than 10 minutes
to read and think about one article.

What do you consider reasonable? 8 hours for a forum site where a
hacker could post death threats in your name, but not spend any of
your money? How about a site where the hacker (possibly your kids
or soon-to-be-ex- wife or her boyfriend) could order football
memorabilia to be sent to *YOUR* address on your credit card, but
not get it shipped anywhere else?

Gordon L. Burditt
Jul 17 '05 #6
Hey,

Thanks for the tips guys. I got my system working and sort of wrapped
my head around the idea of session-based authentication.

I decided to use IP based tracking. You and the following poster warn
against this, but those problems shouldn't apply to my application.
This application is being used on our intranet, so I'm not worried
about dial-up users or users behind a proxy. Having said that, I don't
know if it adds much -- I'm not expecting anybody to sniff SIDs on our
local network, but I guess anything is possible?

To respond to Gordon, I'm not passing plaintext passwords around, only
an MD5 hashed password. But your comment I found a little unsettling:
are you implying that session variables (besides the session id) are
transmitted over the network? I assumed that they were only resident in
the server's memory, and the SID was the only data that was carried
back and forth.

What I am *now* concerned about is this: I'm not the only user with
write access on our web server. So if my authentication simply consists
of placing an authentication flag in the session variables, somebody
could write a PHP script in another directory on the server which
starts a new session, fills out that flag, and then redirects the
browser to my supposedly "protected" page. The only thing preventing
this is not knowing the name of that flag, but if I ever released my
code to anybody else then my site would be compromised.

So right now I'm sticking with checking the database on each page. My
app doesn't have a lot of simultaneous users (not many users totally
actually, its a backend tool for the IT dept.), and the intranet web
server in general runs at no load, so this overhead isn't a problem.

Really, the application isn't even so important that I expect people to
go to these lengths to crack it. My real goal here is to learn
something, so that if on a future project I really do need to "do it
right", I'll know what that takes.

How does a timeout work? Does PHP do it automatically or do I need to
compare timestamps to decide when the timeout period has elapsed?

Thanks again for all the help

Jul 17 '05 #7
>Thanks for the tips guys. I got my system working and sort of wrapped
my head around the idea of session-based authentication.

I decided to use IP based tracking. You and the following poster warn
against this, but those problems shouldn't apply to my application.
This application is being used on our intranet, so I'm not worried
about dial-up users or users behind a proxy. Having said that, I don't
know if it adds much -- I'm not expecting anybody to sniff SIDs on our
local network, but I guess anything is possible?
Sniffing SIDs is much easier on a LAN than doing it from a different
country.
To respond to Gordon, I'm not passing plaintext passwords around, only
an MD5 hashed password. But your comment I found a little unsettling:
are you implying that session variables (besides the session id) are
transmitted over the network? I assumed that they were only resident in
the server's memory, and the SID was the only data that was carried
back and forth.
One (BAD!!) alternative to depending on sessions and having the
user enter a password on each page is to hide the password in a
hidden field on the next page, so it can be used again. This
involves sending the password in plaintext TO the user, and again
when the user submits the page, which makes it a really BAD idea.

However, if someone refuses to trust the secrecy of session IDs,
and they don't want the user to enter the password every page,
they're pretty much stuck with it. But since they don't trust the
secrecy of session IDs, I guess they don't trust the secrecy of
passwords either. Now they are REALLY stuck.

This is *NOT* what session variables do, unless you also include
the values of session variables in the output. Session variables
stay on the server unless your scripts do something with them. Now,
some session variables can be safely output to the page: "You now
have 3 items in your shopping cart, which are ...". Passwords
aren't one of these.
What I am *now* concerned about is this: I'm not the only user with
write access on our web server. So if my authentication simply consists
of placing an authentication flag in the session variables, somebody
could write a PHP script in another directory on the server which
starts a new session, fills out that flag, and then redirects the
browser to my supposedly "protected" page. The only thing preventing
this is not knowing the name of that flag, but if I ever released my
code to anybody else then my site would be compromised.
Session IDs are normally stored in cookies. A cookie in the XYZ
domain shouldn't be passed to you in the DEF domain. However, you
can't count on users not manually inserting cookies into their
browsers.

You can make the name of the "authenticated" flag configurable.
That's not a very good or secure solution.

This is a problem. It is possible to write a session handler which
stores session variables in your database rather than in a common
directory of files. Now, how do you keep your DB password secret
in such an environment, such that YOUR scripts can use it, but the
other guy's scripts can't, both running on the same instance of
Apache and PHP? The DB password issue is relevant even if you
don't use sessions or don't put sessions in the DB - anyone who
can write to your DB can add themselves to the user list.

If you were concerned before, you should be really frightened now.

About the only semi-good answer I've heard for multiple potentially
mutually-hostile customers on the same box involves (a) you have
to trust the admin of the box to set this up, and (b) the admin
puts the parameters for your DB in the Apache config file inside a
<Virtualhost> directive, so each site only sees its own password,
(c) use the default setup to connect to the DB, and (d) I think
safe mode has to be on and no site is allowed to access the Apache
config file and preferably no site is allowed to open files in
another user's tree. Some of this may go out the window if any
user is allowed to write and install his own CGIs not subject
to PHP safe mode.
So right now I'm sticking with checking the database on each page. My
app doesn't have a lot of simultaneous users (not many users totally
actually, its a backend tool for the IT dept.), and the intranet web
server in general runs at no load, so this overhead isn't a problem. Really, the application isn't even so important that I expect people to
go to these lengths to crack it. My real goal here is to learn
something, so that if on a future project I really do need to "do it
right", I'll know what that takes. How does a timeout work? Does PHP do it automatically or do I need to
compare timestamps to decide when the timeout period has elapsed?


php.ini has some parameters for automatic session cleanup, primarily
for getting rid of long-abandoned sessions so your disk doesn't
fill up or the number of files in a single directory doesn't make
the system slow to a crawl. You can also put a timestamp (probably
updated on each page hit) in the session and compare yourself, if
you want to be sure of on-time expiration.

Gordon L. Burditt
Jul 17 '05 #8
In article <11*************@corp.supernews.com>,
go***********@burditt.org (Gordon Burditt) wrote:
Session IDs are normally stored in cookies. A cookie in the XYZ
domain shouldn't be passed to you in the DEF domain. However, you
can't count on users not manually inserting cookies into their
browsers.
I didn't make it clear: other users are able to post websites on our
intranet server (in other directories, of course). Thus they would be
writing cookies on the same domain.
You can make the name of the "authenticated" flag configurable.
That's not a very good or secure solution.

This is a problem. It is possible to write a session handler which
stores session variables in your database rather than in a common
directory of files. Now, how do you keep your DB password secret
in such an environment, such that YOUR scripts can use it, but the
other guy's scripts can't, both running on the same instance of
Apache and PHP? The DB password issue is relevant even if you
don't use sessions or don't put sessions in the DB - anyone who
can write to your DB can add themselves to the user list.
Youch, sounds rough. I guess the real answer is that one must administer
one's own server if they want airtight security? Although this isn't
possible for the project I'm working on I think the level of security I
have reached already is good enough.
If you were concerned before, you should be really frightened now.

About the only semi-good answer I've heard for multiple potentially
mutually-hostile customers on the same box involves (a) you have

Hopefully nobody in our IT department will be hostile towards me!

Thanks for the advice, Gordon.

--
|\/| /| |2 |<
mehaase(at)sas(dot)upenn(dot)edu
Jul 17 '05 #9
Mark H wrote:
Hey all--

I'm building a database and I basically need to keep out people who
aren't authorized, but it's not like I need top security here. I'm just
doing basic user/pass of a SQL database, and when a user authenticates
I start a session for him.

My question is, is there any way for a hacker to easily start a session
without having logged in? For instance, if I save the user name and IP
address in the session will it be relatively tough to fake a session?

Sorry if this is a dumb question, I really don't know much about this
yet.


If you're using Apache, you could also use mod_auth_mysql (on
sourceforge) to do the authorization/authentication for you.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #10
>> Session IDs are normally stored in cookies. A cookie in the XYZ
domain shouldn't be passed to you in the DEF domain. However, you
can't count on users not manually inserting cookies into their
browsers.


I didn't make it clear: other users are able to post websites on our
intranet server (in other directories, of course). Thus they would be
writing cookies on the same domain.


So maybe you should get your own domain for this purpose. A subdomain
of your current domain might work (e.g. www2.mydomain.com). Since
you've only got one webserver, you're stuck with that, but Apache
does virtualhosting nicely. I don't recall the rules about passing
cookies between parent domains and subdomains.

Gordon L. Burditt
Jul 17 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: The Plankmeister | last post by:
Hi... I'm writing a website builder. There are two 'halves' of it, codewise: The admin pages and the public pages. I intend to use sessions to hold information about validated users (to modify...
2
by: paul brown | last post by:
Is there a way to authenticate using Apache's basic authentication without having the pop-up? For instance, can a person use a form that authenticates using the built-in authentication? Does that...
1
by: Rob | last post by:
I have an ASP.NET application that uses forms-based authentication. A user wishes to be able to run multiple sessions of this application simultaneously from the user's client machine. The...
3
by: Martin | last post by:
Dear fellow ASP.NET programmer, I stared using forms authentication and temporarily used a <credentials> tag in web.config. After I got it working I realized this wasn't really practical. I...
1
by: David Krussow | last post by:
I have implemented ASP.NET Forms authentication in a test app. The app has a number of forms - only one of which requires authentication in order to be viewed (the "secured form"). Everything works...
5
by: SOS | last post by:
Hi guys, how can i use of sessions to authenticate users ? before, i used of cookies and i store users profile in the cookies but now i need to do same work with sessions. Thanx
2
by: Raghuram | last post by:
I have a problem related to the page authentication. . . i am trying to implement the Windows authentication in the project, I am using the LDAP services to fetch the details from the widows...
7
by: mircu | last post by:
Hi, I noticed weird behaviour with the site that is using forms authentication. I am logged to the site from the same machine from two browsers (opened separately, not ctrl-N) as different users...
6
by: Notgiven | last post by:
I am considering a large project and they currently use LDAP on MS platform. It would be moved to a LAMP platform. OpenLDAP is an option though I have not used it before. I do feel fairly...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.