Can SID be trusted?
am 15.01.2008 03:24:30 von Sebastian Lisken
Hi, I'm in the process of securing a PHP/MySQL website by making sure
all strings that can at least possibly be manipulated from the outside
are passed through the appropriate escaping functions and/or validated
against patterns. In the most canonical cases, SQL strings supplied from
the outside are handled by mysql_real_escape_string, HTML snippets by
htmlentities, GET parameters in query strings by rawencodeurl. What I'm
unsure about is whether SID needs to be treated. It's the variable used
most often, so I guess I could improve efficiency a bit by not adding
an escaping functions in snippets such as
">
Is there a known scenario in which an attacker could set SID to contain,
say, HTML that could then be used in an XSS attack?
Thanks for your opinions
Sebastian Lisken
Re: Can SID be trusted?
am 15.01.2008 09:39:11 von Erwin Moller
Sebastian Lisken wrote:
Hi Sebastian,
> Hi, I'm in the process of securing a PHP/MySQL website by making sure
> all strings that can at least possibly be manipulated from the outside
> are passed through the appropriate escaping functions and/or validated
> against patterns. In the most canonical cases, SQL strings supplied from
> the outside are handled by mysql_real_escape_string,
Your app accepts complete SQL-commands from the outside?
Are you sure that is allright?
I mean, why bother to escape SQL, if I can simple fire a:
DELETE FROM tblusers;
HTML snippets by
> htmlentities, GET parameters in query strings by rawencodeurl. What I'm
> unsure about is whether SID needs to be treated. It's the variable used
> most often, so I guess I could improve efficiency a bit by not adding
> an escaping functions in snippets such as
>
> ">
>
> Is there a known scenario in which an attacker could set SID to contain,
> say, HTML that could then be used in an XSS attack?
No, not an XSS attack. The PHPSESSID is only used to maintain a session
with some client.
But in case you wrote your own sessionhandlers, you should take precautions.
If you use default sessions (file) don't worry.
Of course you should always worry about sessionstealing.
If person A gets the sessionid of person B, person A can pretend to be
person B for the duration of the session. (For more details see
sessionpages on www.php.net. The scenario is named 'session fixation'.)
Regards,
Erwin Moller
>
> Thanks for your opinions
>
> Sebastian Lisken
>
Re: Can SID be trusted?
am 15.01.2008 14:01:25 von Sebastian Lisken
Erwin Moller wrote:
> Your app accepts complete SQL-commands from the outside?
> Are you sure that is allright?
Of course not. When I wrote "SQL strings" I meant just that: user input
that becomes a string as regarded by SQL's grammar. Not a keyword or a
number. Something like
"SELECT FROM tblusers WHERE name='" . mysql_real_escape_string($_GET['username']) . "';"
Just as a different example, if the value becomes a number I'd use
it without single quotes or an escape function but validate it using
is_numeric instead.
> No, not an XSS attack. The PHPSESSID is only used to maintain a session
> with some client.
> But in case you wrote your own sessionhandlers, you should take precautions.
> If you use default sessions (file) don't worry.
>
> Of course you should always worry about sessionstealing.
I have of course read up on all of this. I'm not saying I'd never need
to remind myself of that issue again, or that further thoughts are not
welcome, but I'd really prefer this thread not to become a general PHP
security roundup. I'm looking for answers to my specific question:
Could SID be manipulated to contain something nasty instead of
"Name_of_session_id_variable=hexadecimal_session_id", so that it might
warrant escaping?
Sebastian
Re: Can SID be trusted?
am 15.01.2008 15:00:59 von brunormbarros
> Could SID be manipulated to contain something nasty instead of
> "Name_of_session_id_variable=hexadecimal_session_id", so that it might
> warrant escaping?
>
> Sebastian
Not nasty things, but session stealing. If you are an ADMIN of the
website and your SSID is 55555, and you are on the website and see
something nice to tell me, a nobody in your website, you will send:
www.mysite.com/page.php?SID=55555
And I will be on the page with Administrator Permissions. Which is
awful. I myself use Cookies for SID, so the dumb users don't make
errors like what I've just told you about.
Re: Can SID be trusted?
am 15.01.2008 15:08:03 von Christian Welzel
Bruno Rafael Moreira de Barros wrote:
> awful. I myself use Cookies for SID, so the dumb users don't make
> errors like what I've just told you about.
But then make sure, your website is not vulnerable to session riding
by using the stored cookie.
--
MfG, Christian Welzel aka Gawain@Regenbogen
GPG-Key: http://www.camlann.de/key.asc
Fingerprint: 4F50 19BF 3346 36A6 CFA9 DBDC C268 6D24 70A1 AD15
Re: Can SID be trusted?
am 15.01.2008 17:17:45 von Sebastian Lisken
Bruno Rafael Moreira de Barros wrote:
> Not nasty things, but session stealing.
I know about session stealing. I also know that the session ID can be
transmitted via a query string parameter or via a cookie if the browser
permits it. I presume you know that SID reverts to an empty string in
the latter case.
Sebastian
Re: Can SID be trusted?
am 15.01.2008 18:01:02 von Captain Paralytic
On 15 Jan, 16:17, Sebastian Lisken
deletethis.de> wrote:
> I also know that the session ID can be
> transmitted via a query string parameter or via a cookie if the browser
> permits it. I presume you know that SID reverts to an empty string in
> the latter case.
Not what I have seen.
Re: Can SID be trusted?
am 16.01.2008 04:44:10 von Sebastian Lisken
I wrote:
> > I also know that the session ID can be
> > transmitted via a query string parameter or via a cookie if the browser
> > permits it. I presume you know that SID reverts to an empty string in
> > the latter case.
Captain Paralytic wrote:
> Not what I have seen.
You can read http://php.net/manual/en/ref.session.php íf you need to be
convinced there. Now, could we get back to the subject? If you remember,
I'm wondering if SID can be manipulated by an attacker to contain
something that might need escaping when included in HTML such as in
Any opinions on that particular subject are more than welcome still, but
I'm beginning to believe that no escaping (i.e. "treating" the value with
rawurlencode or htmlentities) is required.
Sebastian
Re: Can SID be trusted?
am 16.01.2008 04:53:22 von Jerry Stuckle
Sebastian Lisken wrote:
> I wrote:
>>> I also know that the session ID can be
>>> transmitted via a query string parameter or via a cookie if the browser
>>> permits it. I presume you know that SID reverts to an empty string in
>>> the latter case.
>
> Captain Paralytic wrote:
>> Not what I have seen.
>
> You can read http://php.net/manual/en/ref.session.php íf you need to be
> convinced there. Now, could we get back to the subject? If you remember,
> I'm wondering if SID can be manipulated by an attacker to contain
> something that might need escaping when included in HTML such as in
>
>
>
> Any opinions on that particular subject are more than welcome still, but
> I'm beginning to believe that no escaping (i.e. "treating" the value with
> rawurlencode or htmlentities) is required.
>
> Sebastian
>
>
You're correct that SID is not set if the session id was stored in a
cookie. However, the question is - why are you even doing this? If
properly configured, PHP handles sessions quite well. All you need to
do is issue a session_start() at the beginning of each page where you
use sessions.
And sure, anything CAN be manipulated - theoretically. But the default
PHP session id is a long alphanumeric string. It would be virtually
impossible to manipulate it unless you were somewhere in the path
between the client and the server. And not even then if it's a secure
connection.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Can SID be trusted?
am 16.01.2008 09:44:50 von Erwin Moller
Sebastian Lisken wrote:
> Erwin Moller wrote:
>> Your app accepts complete SQL-commands from the outside?
>> Are you sure that is allright?
>
> Of course not.
Hi Sebastian,
Of course not?
Well, appearently not for you, but I see often code that transmits full
SQL around like that. Bad idea, but you know that allready. ;-)
(Please remember it is hard to tell what a poster knows based on one
posting.)
When I wrote "SQL strings" I meant just that: user input
> that becomes a string as regarded by SQL's grammar. Not a keyword or a
> number. Something like
>
> "SELECT FROM tblusers WHERE name='" . mysql_real_escape_string($_GET['username']) . "';"
>
Looks good.
> Just as a different example, if the value becomes a number I'd use
> it without single quotes or an escape function but validate it using
> is_numeric instead.
>
>> No, not an XSS attack. The PHPSESSID is only used to maintain a session
>> with some client.
>> But in case you wrote your own sessionhandlers, you should take precautions.
>> If you use default sessions (file) don't worry.
>>
>> Of course you should always worry about sessionstealing.
>
> I have of course read up on all of this. I'm not saying I'd never need
> to remind myself of that issue again, or that further thoughts are not
> welcome, but I'd really prefer this thread not to become a general PHP
> security roundup. I'm looking for answers to my specific question:
>
> Could SID be manipulated to contain something nasty instead of
> "Name_of_session_id_variable=hexadecimal_session_id", so that it might
> warrant escaping?
As I said: Only if you use something else than default sessions,
especially databased handled session storage.
Here is an example from my own code:
// Change the save_handler to use our sessionhandlers
session_set_save_handler (
'MySession_open',
'MySession_close',
'MySession_read',
'MySession_write',
'MySession_destroy',
'MySession_gc');
And then for example from MySession_read():
function MySession_read($ses_id) {
$SQL_session = "SELECT session_lock, session_data FROM tblsession
WHERE (session_id='".$ses_id."');";
.... etc
}
The above MySession_read is a bad example, since it does take $ses_id
straight from the cookie (or URL, or post).
I have seen such in productionenvironments.
Solution is simple of course: check the $ses_id before use in SQL.
Rrgards,
Erwin Moller
>
> Sebastian
>
Re: Can SID be trusted?
am 16.01.2008 19:42:22 von Sebastian Lisken
Erwin Moller wrote:
> (Please remember it is hard to tell what a poster knows based on one
> posting.)
That's true - thanks for taking the time to find out. :-)
> // Change the save_handler to use our sessionhandlers
Interesting example, that is indeed an area where I have little
knowledge (although I've seen an example of custom session handlers
somewhere). On the other hand, when it comes to escaping, it's obviously
the very same principle that applies.
Thanks
Sebastian
Re: Can SID be trusted?
am 16.01.2008 20:29:58 von Sebastian Lisken
Jerry Stuckle wrote:
> You're correct that SID is not set if the session id was stored in a
> cookie. However, the question is - why are you even doing this? If
> properly configured, PHP handles sessions quite well. All you need to
> do is issue a session_start() at the beginning of each page where you
> use sessions.
This was in the code I took over, there are numerous examples like
>>
The obvious purpose is to pass on the session ID from one page
to the other. I hadn't done this before so I'm glad you're asking
about it. I have now read the section "Passing the Session ID" in
http://www.php.net/manual/en/ref.session.php and it says that the ID is
passed on transparently if session.use_trans_sid is enabled. I can only
guess that the code was developed in a context where it wasn't. As it
turns out, on my WAMP 5 installation it is disabled too. I've enabled
it, taken away the echo SID; ?> part from one of my links, and seen
the effect of the option. Thanks for educating me there, but with that
experience I'd say it's good practice not to rely on the option (I don't
even know what the setting is on the production server that my work will
be transferred to, but the site has switched servers before so I don't
want to rely on the setting there anyway).
> And sure, anything CAN be manipulated - theoretically. But the default
> PHP session id is a long alphanumeric string. It would be virtually
> impossible to manipulate it unless you were somewhere in the path
> between the client and the server. And not even then if it's a secure
> connection.
If you're bringing in direct manipulation of HTTP packets somewhere
between the server and client then of course everything is possible (as
you say, SSL would be the counter-measure of choice but it's not in use
here). So if we have to go that far to construct an attack on SID then
it's probably not something I should worry about. Password sniffing would
be the more likely thing an attacker would do if they could intercept
HTTP communications at all.
Thanks
Sebastian
Re: Can SID be trusted?
am 16.01.2008 21:25:23 von Christian Welzel
Sebastian Lisken wrote:
> guess that the code was developed in a context where it wasn't. As it
> turns out, on my WAMP 5 installation it is disabled too. I've enabled
This is what the debian php5.ini says about use_trans_sid:
; trans sid support is disabled by default.
; Use of trans sid may risk your users security.
; Use this option with caution.
; - User may send URL contains active session ID
; to other person via. email/irc/etc.
; - URL that contains active session ID may be stored
; in publically accessible computer.
; - User may access your site with the same session ID
; always using URL stored in browser's history or bookmarks.
session.use_trans_sid = 0
So your opens your application
> to exactly the facts mentioned above as it mimics session_trans_sid.
No, my code doesn't make a difference.
Either cookies are enabled: then SID is an empty string and all that
"my" code (it's not mine) adds is the question mark (this is not
pleasing from a cosmetic point of view, but not the issue you mention)
Or cookies are not enabled: then it's *necessary* to use the HTTP
request to pass on the session ID, with all the risks you mention. If
GET parameters are used, this can be done either with "my" code or with
use_trans_sid, they have the same effect. If you say GET parameters
shouldn't be used, what is your alternative?
I *am* aware of the risks of session fixation and stealing. There's
no simple way to avoid them (cookies instead of GET parameters are not
perfect protection and not always available). I wasn't going to go into
that issue at first - hopefully I've made it clear what my specific
question was, but I'm rather confident about the answer to that by
now. So we can discuss attacks on the session (rather than on the
value of SID for XSS purposes) if you want. But please, let's not make
quick judgements based on short remarks in some php.ini file, but read
http://phpsec.org/projects/guide/4.html (which I had before I embarked
on this task) and move the discussion on from there.
Sebastian
Re: Can SID be trusted?
am 17.01.2008 05:12:52 von Jerry Stuckle
Sebastian Lisken wrote:
> Jerry Stuckle wrote:
>> You're correct that SID is not set if the session id was stored in a
>> cookie. However, the question is - why are you even doing this? If
>> properly configured, PHP handles sessions quite well. All you need to
>> do is issue a session_start() at the beginning of each page where you
>> use sessions.
>
> This was in the code I took over, there are numerous examples like
>>>
>
> The obvious purpose is to pass on the session ID from one page
> to the other. I hadn't done this before so I'm glad you're asking
> about it. I have now read the section "Passing the Session ID" in
> http://www.php.net/manual/en/ref.session.php and it says that the ID is
> passed on transparently if session.use_trans_sid is enabled. I can only
> guess that the code was developed in a context where it wasn't. As it
> turns out, on my WAMP 5 installation it is disabled too. I've enabled
> it, taken away the echo SID; ?> part from one of my links, and seen
> the effect of the option. Thanks for educating me there, but with that
> experience I'd say it's good practice not to rely on the option (I don't
> even know what the setting is on the production server that my work will
> be transferred to, but the site has switched servers before so I don't
> want to rely on the setting there anyway).
>
I always rely on it. If your hosting company doesn't support it, get a
new hosting company. It's pretty standard in PHP. Every host I know of
has it enabled.
>> And sure, anything CAN be manipulated - theoretically. But the default
>> PHP session id is a long alphanumeric string. It would be virtually
>> impossible to manipulate it unless you were somewhere in the path
>> between the client and the server. And not even then if it's a secure
>> connection.
>
> If you're bringing in direct manipulation of HTTP packets somewhere
> between the server and client then of course everything is possible (as
> you say, SSL would be the counter-measure of choice but it's not in use
> here). So if we have to go that far to construct an attack on SID then
> it's probably not something I should worry about. Password sniffing would
> be the more likely thing an attacker would do if they could intercept
> HTTP communications at all.
>
> Thanks
>
> Sebastian
>
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Can SID be trusted?
am 17.01.2008 05:14:04 von Jerry Stuckle
Christian Welzel wrote:
> Sebastian Lisken wrote:
>
>> guess that the code was developed in a context where it wasn't. As it
>> turns out, on my WAMP 5 installation it is disabled too. I've enabled
>
> This is what the debian php5.ini says about use_trans_sid:
>
> ; trans sid support is disabled by default.
> ; Use of trans sid may risk your users security.
> ; Use this option with caution.
> ; - User may send URL contains active session ID
> ; to other person via. email/irc/etc.
> ; - URL that contains active session ID may be stored
> ; in publically accessible computer.
> ; - User may access your site with the same session ID
> ; always using URL stored in browser's history or bookmarks.
> session.use_trans_sid = 0
>
> So your
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Can SID be trusted?
am 17.01.2008 05:15:19 von Jerry Stuckle
Sebastian Lisken wrote:
> Christian Welzel wrote:
>> This is what the debian php5.ini says about use_trans_sid:
>>
>> ; trans sid support is disabled by default.
>> ; Use of trans sid may risk your users security.
>> ; Use this option with caution.
>> ; - User may send URL contains active session ID
>> ; to other person via. email/irc/etc.
>> ; - URL that contains active session ID may be stored
>> ; in publically accessible computer.
>> ; - User may access your site with the same session ID
>> ; always using URL stored in browser's history or bookmarks.
>> session.use_trans_sid = 0
>
>> So your
> pleasing from a cosmetic point of view, but not the issue you mention)
>
> Or cookies are not enabled: then it's *necessary* to use the HTTP
> request to pass on the session ID, with all the risks you mention. If
> GET parameters are used, this can be done either with "my" code or with
> use_trans_sid, they have the same effect. If you say GET parameters
> shouldn't be used, what is your alternative?
>
And if PHP is configured correctly, it will do this for you. No need to
do it yourself. All of my PHP sites work fine whether cookies are
enabled or disabled.
> I *am* aware of the risks of session fixation and stealing. There's
> no simple way to avoid them (cookies instead of GET parameters are not
> perfect protection and not always available). I wasn't going to go into
> that issue at first - hopefully I've made it clear what my specific
> question was, but I'm rather confident about the answer to that by
> now. So we can discuss attacks on the session (rather than on the
> value of SID for XSS purposes) if you want. But please, let's not make
> quick judgements based on short remarks in some php.ini file, but read
> http://phpsec.org/projects/guide/4.html (which I had before I embarked
> on this task) and move the discussion on from there.
>
> Sebastian
>
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Can SID be trusted?
am 17.01.2008 05:57:23 von Sebastian Lisken
Jerry Stuckle wrote:
[session.use_trans_sid]
> I always rely on it. If your hosting company doesn't support it, get a
> new hosting company. It's pretty standard in PHP. Every host I know of
> has it enabled.
Well, I won't remove hundreds of occurrences of SID just to arrive at
code that produces the same results if the option is on but breaks if
it isn't. Why do the work just to get code that depends on an option I
could previously ignore? As seems to be the case, there's no reason to
touch those occurrences for security reasons so I'm not going to invent
a new reason now. If I was starting from scratch and deciding whether to
produce these pieces of code or not, then it might be another story. And
I won't need to bully my client about changing their hosts, which I'm
not in a position to do anyway. (The existing host might have the option
enabled for all I know, but I don't care.)
Sebastian
Re: Can SID be trusted?
am 17.01.2008 14:41:18 von Jerry Stuckle
Sebastian Lisken wrote:
> Jerry Stuckle wrote:
> [session.use_trans_sid]
>> I always rely on it. If your hosting company doesn't support it, get a
>> new hosting company. It's pretty standard in PHP. Every host I know of
>> has it enabled.
>
> Well, I won't remove hundreds of occurrences of SID just to arrive at
> code that produces the same results if the option is on but breaks if
> it isn't. Why do the work just to get code that depends on an option I
> could previously ignore? As seems to be the case, there's no reason to
> touch those occurrences for security reasons so I'm not going to invent
> a new reason now. If I was starting from scratch and deciding whether to
> produce these pieces of code or not, then it might be another story. And
> I won't need to bully my client about changing their hosts, which I'm
> not in a position to do anyway. (The existing host might have the option
> enabled for all I know, but I don't care.)
>
> Sebastian
>
>
I wouldn't have put all that crap in there in the first place, and I
definitely would strip it out. It's just something more which has to
be processed and maintained.
And I don't bully my clients. But I do make recommendations when they
need to change hosts, and tell them why. That's what they pay me for.
I care about my clients.
But then I also understand what I'm doing before creating "hundreds of
occurrences" of something. They pay me to write good code.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Can SID be trusted?
am 17.01.2008 15:39:17 von Sebastian Lisken
Jerry Stuckle wrote:
> I care about my clients.
Okay - I thought I'd detected a slightly different tone in your comments
here, but a newsgroup post is not a client contact of course.
> But I do make recommendations when they
> need to change hosts, and tell them why. That's what they pay me for.
> I wouldn't have put all that crap in there in the first place, and I
> definitely would strip it out. It's just something more which has to
> be processed and maintained.
Your strong opinion is appreciated. (Seriously.) But like I said, I'm
not in a position to advocate for a change of hosts. The project is on a
university server and I'm taking it over at a very late stage.
> But then I also understand what I'm doing before creating "hundreds of
> occurrences" of something. They pay me to write good code.
Yes, several people have put work in over a few years and the sole focus
must have been to "get it to work". I'm not saying it was the best choice
to put "that crap" in, I do see some arguments against this but some
for it too (see previous post). I wouldn't have done it in the exact
same way though. I'd be interested to understand better why you feel
so strongly, which aspect is it you don't like - larger code? You do see
that the effect of adding SID "manually" is the same as with the option -
adding a GET parameter only if cookies are disabled - except for an
unnecessary "?" or "&" in "my" version (which I would have taken care
to avoid if it really was my code) if cookies are enabled and SID is
therefore empty?
Sebastian
Re: Can SID be trusted?
am 17.01.2008 18:26:00 von Michael Fesser
..oO(Sebastian Lisken)
>Christian Welzel wrote:
>> This is what the debian php5.ini says about use_trans_sid:
>>
>> ; trans sid support is disabled by default.
>> ; Use of trans sid may risk your users security.
>> ; Use this option with caution.
>> ; - User may send URL contains active session ID
>> ; to other person via. email/irc/etc.
>> ; - URL that contains active session ID may be stored
>> ; in publically accessible computer.
>> ; - User may access your site with the same session ID
>> ; always using URL stored in browser's history or bookmarks.
>> session.use_trans_sid = 0
>
>> So your
>pleasing from a cosmetic point of view, but not the issue you mention)
>
>Or cookies are not enabled: then it's *necessary* to use the HTTP
>request to pass on the session ID, with all the risks you mention. If
>GET parameters are used, this can be done either with "my" code or with
>use_trans_sid, they have the same effect. If you say GET parameters
>shouldn't be used, what is your alternative?
Cookies. For sessions I _always_ require a cookie, I don't use URL-SIDs
anymore for the reasons mentioned above. Cookies are enabled by default
in most browsers, and people who are able to configure their browser as
they want should know enough to at least accept session cookies. If they
don't even do that, then it's their own problem, not mine.
Micha
Re: Can SID be trusted?
am 17.01.2008 18:26:00 von Michael Fesser
..oO(Jerry Stuckle)
>Sebastian Lisken wrote:
>
>> The obvious purpose is to pass on the session ID from one page
>> to the other. I hadn't done this before so I'm glad you're asking
>> about it. I have now read the section "Passing the Session ID" in
>> http://www.php.net/manual/en/ref.session.php and it says that the ID is
>> passed on transparently if session.use_trans_sid is enabled. I can only
>> guess that the code was developed in a context where it wasn't. As it
>> turns out, on my WAMP 5 installation it is disabled too. I've enabled
>> it, taken away the echo SID; ?> part from one of my links, and seen
>> the effect of the option. Thanks for educating me there, but with that
>> experience I'd say it's good practice not to rely on the option (I don't
>> even know what the setting is on the production server that my work will
>> be transferred to, but the site has switched servers before so I don't
>> want to rely on the setting there anyway).
>>
>
>I always rely on it. If your hosting company doesn't support it, get a
>new hosting company. It's pretty standard in PHP. Every host I know of
>has it enabled.
All session configuration directives are marked as "PHP_INI_ALL", so you
can change them even with ini_set() at the beginning of your scripts.
Micha
Re: Can SID be trusted?
am 17.01.2008 20:47:20 von Jerry Stuckle
Sebastian Lisken wrote:
> Jerry Stuckle wrote:
>
>> I care about my clients.
>
> Okay - I thought I'd detected a slightly different tone in your comments
> here, but a newsgroup post is not a client contact of course.
>
>> But I do make recommendations when they
>> need to change hosts, and tell them why. That's what they pay me for.
>
>> I wouldn't have put all that crap in there in the first place, and I
>> definitely would strip it out. It's just something more which has to
>> be processed and maintained.
>
> Your strong opinion is appreciated. (Seriously.) But like I said, I'm
> not in a position to advocate for a change of hosts. The project is on a
> university server and I'm taking it over at a very late stage.
>
>> But then I also understand what I'm doing before creating "hundreds of
>> occurrences" of something. They pay me to write good code.
>
> Yes, several people have put work in over a few years and the sole focus
> must have been to "get it to work". I'm not saying it was the best choice
> to put "that crap" in, I do see some arguments against this but some
> for it too (see previous post). I wouldn't have done it in the exact
> same way though. I'd be interested to understand better why you feel
> so strongly, which aspect is it you don't like - larger code? You do see
> that the effect of adding SID "manually" is the same as with the option -
> adding a GET parameter only if cookies are disabled - except for an
> unnecessary "?" or "&" in "my" version (which I would have taken care
> to avoid if it really was my code) if cookies are enabled and SID is
> therefore empty?
>
> Sebastian
>
>
It means more code, higher maintenance costs and opens the session to
stealing.
Unlike Micha, I don't always *require* cookies. But if the user decides
to disable cookies, he/she has to suffer the possible consequences.
Now if it is something like a shopping cart, then yes - I require cookies.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Can SID be trusted?
am 17.01.2008 22:18:19 von Sebastian Lisken
Jerry Stuckle wrote:
> It means more code, higher maintenance costs and opens the session to
> stealing.
There's something I don't seem to be able to get into yours our Micha's
head, however hard I'm trying.
So, I'll have say it again:
If PHP uses cookies for session management (because it is configured to
try and the browser allows it), SID is an empty string.
Therefore:
If cookies are used, no SID in server logs, links, bookmarks ... etc.
Therefore:
Using SID does not increase the risks of session stealing. The risk is
there, I am aware of it. But I'm not increasing it in the slightest by
using SID in the described way.
Okay?
Now I'm happy to discuss session stealing for fixation, measures against
that. Or Jerry's other arguments against using SID, which have their
merit. (Well, not cost in this case, because here *removing* all those
SIDs would be costly.) Just as along as we're clear:
Using SID does not increase the risk of sessions ending up as part of
URLS.
Sebastian
Re: Can SID be trusted?
am 17.01.2008 23:16:28 von Jerry Stuckle
Sebastian Lisken wrote:
> Jerry Stuckle wrote:
>> It means more code, higher maintenance costs and opens the session to
>> stealing.
>
> There's something I don't seem to be able to get into yours our Micha's
> head, however hard I'm trying.
>
> So, I'll have say it again:
>
> If PHP uses cookies for session management (because it is configured to
> try and the browser allows it), SID is an empty string.
>
> Therefore:
>
> If cookies are used, no SID in server logs, links, bookmarks ... etc.
>
> Therefore:
>
> Using SID does not increase the risks of session stealing. The risk is
> there, I am aware of it. But I'm not increasing it in the slightest by
> using SID in the described way.
>
> Okay?
>
> Now I'm happy to discuss session stealing for fixation, measures against
> that. Or Jerry's other arguments against using SID, which have their
> merit. (Well, not cost in this case, because here *removing* all those
> SIDs would be costly.) Just as along as we're clear:
>
> Using SID does not increase the risk of sessions ending up as part of
> URLS.
>
> Sebastian
>
>
Until the next time your session gets stolen because someone put the
session id in SID...
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Can SID be trusted?
am 18.01.2008 00:19:33 von Sebastian Lisken
Jerry Stuckle wrote:
> Until the next time your session gets stolen because someone put the
> session id in SID...
Oh, for crying out loud - are you just teasing me? Do you refuse to
take in what I'm trying to make you see? Or could you please explain
how "someone" can "put the session ID in SID"?
If cookies are used (which we all agree is the best option), then SID is
empty. Read The Fine Manual.
If SID does contain the session ID then PHP has decided not to use
cookies to propagate the session ID.
If that is true, then one of the following is true:
- session.use_trans_sid - which you advocate - would add the very same
thing to link addresses automatically that I am adding via SID
- or you propose not propagating the session ID via a GET parameter at
all, in which case please tell me what your alternative is (remember,
the premise is that cookies are not accepted by the browser).
IF, however, the browser accepts cookies, then SID does NOT contain the
session ID.
So where is the added risk?!
Sebastian
Re: Can SID be trusted?
am 18.01.2008 03:27:10 von Jerry Stuckle
Sebastian Lisken wrote:
> Jerry Stuckle wrote:
>> Until the next time your session gets stolen because someone put the
>> session id in SID...
>
> Oh, for crying out loud - are you just teasing me? Do you refuse to
> take in what I'm trying to make you see? Or could you please explain
> how "someone" can "put the session ID in SID"?
>
Very simple. Some programmer comes along and sees there isn't anything
in SID - and, not knowing any better, gets the session id and places it
in there. Do you think you're the only one who well ever work on these
scripts?
> If cookies are used (which we all agree is the best option), then SID is
> empty. Read The Fine Manual.
>
Yep. But that doesn't mean you should increase your exposure. And if
cookies are not active, PHP handles it for you, anyway.
> If SID does contain the session ID then PHP has decided not to use
> cookies to propagate the session ID.
>
> If that is true, then one of the following is true:
>
> - session.use_trans_sid - which you advocate - would add the very same
> thing to link addresses automatically that I am adding via SID
>
> - or you propose not propagating the session ID via a GET parameter at
> all, in which case please tell me what your alternative is (remember,
> the premise is that cookies are not accepted by the browser).
>
I say don't do it at all for important stuff - like private logins. If
cookies aren't accepted, they can't use the site. For sites where it
really doesn't matter if the session id is propagated or not, I let them
use cookies or not.
> IF, however, the browser accepts cookies, then SID does NOT contain the
> session ID.
>
> So where is the added risk?!
>
> Sebastian
>
>
Again - some stupid programmer who doesn't know enough not to screw with
SID gets the session id and places it in there/
But that's OK. It's your code. Your exposure. And your code that
someone else will see at some point in time. If you don't care about
any of that, it's no skin off my back.
We tried to tell you. All you've done is argue. So have fun - but
don't come crying to us when someone hacks your system.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: Can SID be trusted?
am 18.01.2008 06:10:51 von Sebastian Lisken
Jerry Stuckle wrote:
[Having the session ID in SID even when cookies are used]
> Very simple. Some programmer comes along and sees there isn't anything
> in SID - and, not knowing any better, gets the session id and places it
> in there. Do you think you're the only one who well ever work on these
> scripts?
Ah - now at last you are beginning to explain. Thank you. All this time
I was asking about users messing things up, not other programmers. So
forgive me for not being able to make that connection with the very
terse responses you gave before this one.
So, hm, other programmers. Let me think. No - let me read the manual.
http://www.php.net/session
> SID (string)
> Constant containing either the session name and session ID in the
> form of "name=ID" or empty string if session ID was set in an
> appropriate session cookie.
So, it's a constant. The documentation makes it clear that it's a value
that programmers will want to read for informative purposes. Why should
they want to write to it instead and destroy that information?
Actually, the word "constant" should signify something more fundamental
to the open-minded reader. Could it be ...? Yes. SID is read-only. I've
just tried to assign a value to it in a script and got an error. No
surprise really - it doesn't start with a $ either.
Sorry, Jerry, I have seen other threads and realise that you are a
frequent and helpful advisor in this group, but with all due respect -
you are quite wrong in your judgement on SID, and you are in denial about
that. (I do share your argument about code bloat and maintainability, but
I've explained why I'm coming from the opposite direction on that one.)
[Also about SID being empty if cookies are used]
> Yep. But that doesn't mean you should increase your exposure. And if
> cookies are not active, PHP handles it for you, anyway.
Yes, I know PHP handles it for me. I've said so myself.
But I still don't see myself increasing my exposure.
[Passing on Session IDs in situations where cookies won't work]
> I say don't do it at all for important stuff - like private logins. If
> cookies aren't accepted, they can't use the site. For sites where it
> really doesn't matter if the session id is propagated or not, I let them
> use cookies or not.
Yes, that's a reasonable position - but nothing to do with the question
whether I'm using SID or not.
> But that's OK. It's your code. Your exposure. And your code that
> someone else will see at some point in time. If you don't care about
> any of that, it's no skin off my back.
> We tried to tell you. All you've done is argue. So have fun - but
> don't come crying to us when someone hacks your system.
I won't come crying, don't worry. And though it might seem so to you,
I'm honestly not a fan of using SID either. My only reasons for sticking
with it are the ones I've mentioned several times. I don't really want to
argue for it.
All I'm trying to do is achieve an informed debate, where both sides take
in what the other person is saying and, if necessary, explain what they
themselves are saying. Rather than find something to gut-react to and
then go ahead with that reaction. I've had such a hard time trying to
make several people see that this is not about putting the session ID
into URLs in situations where they wouldn't appear normally. And that
I see the risks of them showing up there just as much as you do. That
was quite frustrating. Maybe we are finally making some progress there.
Sebastian
Re: Can SID be trusted?
am 18.01.2008 14:22:13 von ng4rrjanbiah
On Jan 15, 7:24 am, Sebastian Lisken
deletethis.de> wrote:
> Hi, I'm in the process of securing a PHP/MySQL website by making sure
> all strings that can at least possibly be manipulated from the outside
> are passed through the appropriate escaping functions and/or validated
> against patterns. In the most canonical cases, SQL strings supplied from
> the outside are handled by mysql_real_escape_string, HTML snippets by
> htmlentities, GET parameters in query strings by rawencodeurl. What I'm
> unsure about is whether SID needs to be treated. It's the variable used
> most often, so I guess I could improve efficiency a bit by not adding
> an escaping functions in snippets such as
>
> ">
>
> Is there a known scenario in which an attacker could set SID to contain,
> say, HTML that could then be used in an XSS attack?
1. mysql_real_escape_string() is again broken. Use prepare statements
2. Disable trans sid--always use cookies based session
3. Possibly use DB based session handler
4. Some versions of PHP has XSS issues with $_SERVER['PHP_SELF']. So,
use $_SERVER['SCRIPT_NAME']
5. Session Ids can be "fixed". So, if you're concerned use DB based
sessions and use session_regenerate_id()
--
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/
Re: Can SID be trusted?
am 18.01.2008 17:05:17 von Sebastian Lisken
Thanks a lot for your response. I have a few questions/remarks ...
R. Rajesh Jeba Anbiah wrote:
> 1. mysql_real_escape_string() is again broken. Use prepare statements
That sounds like something I should look into. Could you explain or
point to some source on the web? I'd want to know in what sense it is
broken, and although I glanced over PREPARE in the MySQL manual I can't
yet see how that would resolve things. PREPARE seems to be SQL (unless
you are referring to http://www.php.net/pdo-prepare) so I would still
be wondering how to get my string from PHP over to SQL.
> 2. Disable trans sid--always use cookies based session
Yes. I'm not relying on trans sid anyway (there's a lengthy dispute
about that in this thread) but using "manual" insertion of SID to get
the same behaviour. As it happens, the option is off on the server. I
think the message is not about use_trans_sid versus SID, it's independent
of that and more fundamental: require cookies, don't let session IDs
show up in URLs. I agree in principle. Whether it needs to be put into
practice for this site is a matter I need to discuss with my client. They
will need to balance security with compatibility.
> 3. Possibly use DB based session handler
The security requirements are probably not high enough for that (and the
budget not available), but it's something I'll keep in mind.
> 4. Some versions of PHP has XSS issues with $_SERVER['PHP_SELF']. So,
> use $_SERVER['SCRIPT_NAME']
When I did my research I realised I couldn't trust PHP_SELF, so I'm
always escaping it (using htmlentities in the most frequent application,
where PHP_SELF is used for a href value possibly followed by URL
parameters). Using SCRIPT_NAME would be another solution, I agree.
> 5. Session Ids can be "fixed". So, if you're concerned use DB based
> sessions and use session_regenerate_id()
I am introducing session_regenerate_id.
Sebastian
Re: Can SID be trusted?
am 19.01.2008 18:51:34 von ng4rrjanbiah
On Jan 18, 9:05 pm, Sebastian Lisken
deletethis.de> wrote:
> Thanks a lot for your response. I have a few questions/remarks ...
>
> R. Rajesh Jeba Anbiah wrote:
>
> > 1. mysql_real_escape_string() is again broken. Use prepare statements
>
> That sounds like something I should look into. Could you explain or
> point to some source on the web? I'd want to know in what sense it is
> broken, and although I glanced over PREPARE in the MySQL manual I can't
> yet see how that would resolve things. PREPARE seems to be SQL (unless
> you are referring tohttp://www.php.net/pdo-prepare) so I would still
> be wondering how to get my string from PHP over to SQL.
See http://ilia.ws/archives/103-mysql_real_escape_string-versus- Prepared-Statements.html
--
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/