{"id":9661,"date":"2014-03-03T20:30:06","date_gmt":"2014-03-04T01:30:06","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=9661"},"modified":"2014-03-31T15:27:04","modified_gmt":"2014-03-31T20:27:04","slug":"set-secure-cookie-in-apache","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=9661","title":{"rendered":"Set Secure and HttpOnly Cookies in Apache 2.2.4"},"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=\"#Steps\">Steps<\/a>\n\t<\/li>\n\t<li>\n\t\t<a href=\"#Test\">Test<\/a>\n\t\t<ol class='toc-even level-2'>\n\t\t\t<li>\n\t\t\t\t<a href=\"#Before\">Before<\/a>\n\t\t\t<\/li>\n\t\t\t<li>\n\t\t\t\t<a href=\"#After\">After<\/a>\n\t\t\t<\/li>\n\t\t<\/ol>\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=\"Steps\"><h2>Steps<\/h2><\/span>\n<p>* See <a href=\"?p=9656\">this post<\/a> to configure mod_jk module for Apache 2.2 and Tomcat 7<br \/>\n* Make sure mod_headers is loaded:<\/p>\n<pre lang=\"bash\">\r\n# grep mod_headers.so httpd.conf\r\nLoadModule headers_module modules\/mod_headers.so\r\n<\/pre>\n<p>* Add to httpd.conf<br \/>\n<em>Header edit Set-Cookie ^(.*)$ $1;Secure;HttpOnly<\/em><br \/>\n&#8211; or to prevent duplicate HttpOnly tag:<br \/>\n<em>Header edit Set-Cookie &#8220;(?i)^((?:(?!;\\s?HttpOnly).)+)$&#8221; &#8220;$1; HttpOnly&#8221;<\/em><br \/>\n* Restart Apache<\/p>\n<span id=\"Test\"><h2>Test<\/h2><\/span>\n<p>* Install and start Fiddler2<\/p>\n<span id=\"Before\"><h3>Before<\/h3><\/span>\n<p>* Point browser 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_testCookie.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookie-300x280.jpg\" alt=\"mod_jk_testCookie\" width=\"300\" height=\"280\" class=\"aligncenter size-medium wp-image-9664\" srcset=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookie-300x280.jpg 300w, https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookie.jpg 326w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/h6><\/span>\n<p>* Check Fiddler and you should see<br \/>\n<em>Set-Cookie: testname=testvalue<\/em><\/p>\n<span id=\"_1\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookie_fiddler.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookie_fiddler.jpg\" alt=\"mod_jk_testCookie_fiddler\" width=\"257\" height=\"225\" class=\"aligncenter size-full wp-image-9665\" \/><\/a><\/h6><\/span>\n<span id=\"After\"><h3>After<\/h3><\/span>\n<p>* Check Fiddler and you should see<br \/>\n<em>Set-Cookie: testname=testvalue;Secure;HttpOnly<\/em><\/p>\n<span id=\"_2\"><h6><a href=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_fiddler.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jianmingli.com\/wp\/wp-content\/uploads\/2014\/03\/mod_jk_testCookieHttpOnly_fiddler.jpg\" alt=\"mod_jk_testCookieHttpOnly_fiddler\" width=\"275\" height=\"223\" class=\"aligncenter size-full wp-image-9666\" \/><\/a><\/h6><\/span>\n<span id=\"References\"><h2>References<\/h2><\/span>\n<p>* <a href=\"https:\/\/www.owasp.org\/index.php\/HttpOnly\">OWASP httpOnly<\/a><br \/>\n* <a href=\"http:\/\/stackoverflow.com\/questions\/4998398\/add-httponly-flag-to-cookies-on-the-fly-with-apache\">http:\/\/stackoverflow.com\/questions\/4998398\/add-httponly-flag-to-cookies-on-the-fly-with-apache<\/a><br \/>\n* <a href=\"http:\/\/chandank.com\/security\/httponly-secure-cookie-apache\">http:\/\/chandank.com\/security\/httponly-secure-cookie-apache<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Steps * See this post to configure mod_jk module for Apache 2.2 and Tomcat 7 * Make sure mod_headers is loaded: # grep mod_headers.so httpd.conf LoadModule headers_module modules\/mod_headers.so * Add to httpd.conf Header edit Set-Cookie ^(.*)$ $1;Secure;HttpOnly &#8211; or to &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=9661\">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":[468,469,470],"class_list":["post-9661","post","type-post","status-publish","format-standard","hentry","category-apache","tag-apache2","tag-httponly","tag-mod_headers"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-2vP","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/9661","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=9661"}],"version-history":[{"count":6,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/9661\/revisions"}],"predecessor-version":[{"id":9906,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/9661\/revisions\/9906"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}