{"id":9827,"date":"2014-03-17T15:55:20","date_gmt":"2014-03-17T20:55:20","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=9827"},"modified":"2014-03-31T15:25:58","modified_gmt":"2014-03-31T20:25:58","slug":"set-secure-and-httponly-cookies-in-apache-2-0","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=9827","title":{"rendered":"Set Secure and HttpOnly Cookies in Apache 2.0 Using Mod_Security"},"content":{"rendered":"<div class='toc wptoc'>\n<h2>Contents<\/h2>\n<ol class='toc-odd level-1'>\n\t<li>\n\t\t<a href=\"#Versions\">Versions<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Install_mod_security\">Install <em>mod_security<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Append_HttpOnly_Tag_to_Cookies\">Append HttpOnly Tag to Cookies<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Testing\">Testing<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#References\">References<\/a>\n\t<\/li>\n<\/ol>\n<\/ol>\n<\/div>\n<div class='wptoc-end'>&nbsp;<\/div>\n<span id=\"Versions\"><h2>Versions<\/h2><\/span>\n<p>* CentOS 6.2<br \/>\n* Apache 2.0.52<br \/>\n* For <em>Apache 2.2<\/em> and above, see <a href=\"?p=9661\">here<\/a> to use <em>mod_header edit<\/em> function<\/p>\n<span id=\"Install_mod_security\"><h2>Install <em>mod_security<\/h2><\/span>\n<p>* Install with <em>yum<\/em>:<\/p>\n<pre lang=\"bash\">\r\nyum install mod_security\r\n\r\nservice httpd restart\r\n<\/pre>\n<p>* mod_security config file: <em>\/etc\/httpd\/conf.d\/mod_security.conf<\/em><br \/>\n&#8211; check that rule engine is turned on: <em>SecRuleEngine On<\/em><br \/>\n* mod_security rules directory: <em>\/etc\/httpd\/modsecurity.d\/activated_rules<\/em><\/p>\n<span id=\"Append_HttpOnly_Tag_to_Cookies\"><h2>Append HttpOnly Tag to Cookies<\/h2><\/span>\n<p>* Add to <em>\/etc\/httpd\/conf.d\/mod_security.conf<\/em>:<\/p>\n<pre lang=\"xml\">\r\n# Identifies SessiondIDs without HTTPOnly flag and sets the \"http_cookie\" ENV\r\n# Token for Apache to read\r\nSecRule RESPONSE_HEADERS:\/Set-Cookie2?\/ \"!(?i:\\;? ?httponly;?)\" \"id:300001,chain,phase:3,t:none,pass,nolog\"\r\nSecRule MATCHED_VAR \"(?i:(j?sessionid|(php)?sessid|(asp|jserv|jw)?session[-_]?(id)?|cf(id|token)|sid))\" \"t:none,setenv:http_cookie=%{matched_var}\"\r\n\r\n# Now we use the Apache Header directive to set the new data\r\nHeader set Set-Cookie \"%{http_cookie}e; HTTPOnly\" env=http_cookie\r\n<\/IfModule>\r\n<\/pre>\n<span id=\"Testing\"><h2>Testing<\/h2><\/span>\n<p>* See <a href=\"?p=9661\">this post<\/a> on how to setup testing<br \/>\n* Point IE to: <a href=\"http:\/\/openidmbox\/examples\/servlets\/servlet\/CookieExample\">http:\/\/openidmbox\/examples\/servlets\/servlet\/CookieExample<\/a><\/p>\n<span id=\"\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_web_Apache2.0.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_web_Apache2.0-300x255.jpg\" alt=\"mod_jk_testCookieHttpOnly_web_Apache2.0\" width=\"300\" height=\"255\" class=\"aligncenter size-medium wp-image-9832\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_web_Apache2.0-300x255.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_web_Apache2.0.jpg 325w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>* Without mod_security rules:<\/p>\n<span id=\"_1\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_fiddler_Apache2.0.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_fiddler_Apache2.0.jpg\" alt=\"mod_jk_testCookieHttpOnly_fiddler_Apache2.0\" width=\"217\" height=\"107\" class=\"aligncenter size-full wp-image-9833\" \/><\/a><\/h6><\/span>\n<p>* With mod_security rules:<\/p>\n<span id=\"_2\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_fiddler_Apache2.0_modSec.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_fiddler_Apache2.0_modSec.jpg\" alt=\"mod_jk_testCookieHttpOnly_fiddler_Apache2.0_modSec\" width=\"244\" height=\"104\" class=\"aligncenter size-full wp-image-9834\" \/><\/a><\/h6><\/span>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"http:\/\/blog.modsecurity.org\/2008\/12\/fixing-both-missing-httponly-and-secure-cookie-flags.html\">ModSecurity Blog: Fixing Both Missing HTTPOnly and Secure Cookie Flags<\/a><br \/>\n* <a href=\"http:\/\/blog.modsecurity.org\/2008\/12\/helping-protect-cookies-with-httponly-flag.html\">ModSecurity Blog: Helping Protect Cookies with HTTPOnly Flag<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Versions * CentOS 6.2 * Apache 2.0.52 * For Apache 2.2 and above, see here to use mod_header edit function Install mod_security * Install with yum: yum install mod_security service httpd restart * mod_security config file: \/etc\/httpd\/conf.d\/mod_security.conf &#8211; check that &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=9827\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[21],"tags":[475,469],"class_list":["post-9827","post","type-post","status-publish","format-standard","hentry","category-apache","tag-apache2-0","tag-httponly"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-2yv","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/9827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9827"}],"version-history":[{"count":7,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/9827\/revisions"}],"predecessor-version":[{"id":9905,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/9827\/revisions\/9905"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}