How do I set the HttpOnly flag on JSF/Richfaces

六月ゝ 毕业季﹏ 提交于 2019-12-24 04:12:33

问题


I'd like to add the HttpOnly flag to JSF/richfaces cookies, especially the session cookie, to up the level of security on my web app. Any ideas?


回答1:


There may be something that allows you to do this in your servlet engine. This is part of the Servlet 3.0 spec which is yet to be released.




回答2:


FacesContext facesContext = FacesContext.getCurrentInstance().getFacesContext();

HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();

response.addHeader("Set-Cookie", "yourcookiename=yourcookievalue; HTTPOnly");



回答3:


Something like:

response.setHeader("Set-Cookie", "yourcookiename=yourcookievalue; HTTPOnly");

might work in a Java environment. I am not aware of a JSF-specific way to achieve this... sorry

This seems to be not an easy task in Java.




回答4:


I suspect that I'll need to use a filter to add a response wrapper, which'll add the flag to all cookies as they're added by the framework.



来源:https://stackoverflow.com/questions/72304/how-do-i-set-the-httponly-flag-on-jsf-richfaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!