简体   繁体   English

我该如何处理会话URL很长但无法附加JSESSIONID = 389729387392。对此有什么解决方案?

[英]How can I do sessions URL is very long I cannot append JSESSIONID=389729387392.What is the solution for this?

I got the answer for If I disabled the cookies then using URL ReDirect I can pass the JSESSIONID but my URL is already very long as I use the GET method it has constraint. 我得到的答案是:如果我禁用cookie,然后使用URL ReDirect,我可以传递JSESSIONID,但是只要使用具有约束的GET方法,我的URL就已经很长了。 Then how should I use my sessions.I want my application to be very security intensive. 然后我应该如何使用会话。我希望我的应用程序非常安全。 This is one of the question asked to my friend in GOOGLE interview. 这是在GOOGLE面试中向我的朋友问的问题之一。

As far as I understand, your main problem with JSESSIONID in the URL is the total length. 据我了解,URL中JSESSIONID的主要问题是总长度。

Perhaps you should have a closer look at why the length of the URLs are too long in the first place. 也许您应该先仔细看看为什么URL的长度太长。 Since you allready have a session, it is not unlikely you can move some GET parameters to the session. 由于您已经准备好进行会话,因此不太可能将一些GET参数移至该会话。 There are also lots of different way to make shorter URLs for pages (a la mod_rewrite). 还有许多其他方法可以使页面的URL较短(la mod_rewrite)。

With regards to security, JSESSIONID is just as vunerable with HTTP GET as HTTP POST. 关于安全性,JSESSIONID对于HTTP GET和HTTP POST一样易受攻击。 The base64 encoding HTTP POST does is not a security measure at all. base64编码的HTTP POST根本不是安全措施。 The best way to gain a bit more security is to encrypt the transport channel through TLS/SSL, in effect enable HTTPS. 获得更高安全性的最佳方法是通过TLS / SSL加密传输通道,实际上是启用HTTPS。 This will make sure that eavesdropping (or man in the middle attacks) will not have access to the plain text. 这样可以确保窃听(或中间人攻击)无法访问纯文本。

Apart from using one-letter parameter names (eg ?a=value1&b=value2&c=value3 or using RESTFul-like URL's (ie just the pathinfo, no query parameters, eg /value1/value2/value3 , which is accessible by HttpServletRequest#getPathInfo() in the servlet) instead of ?name1=value1&name2=value2&name3=value3 , you can also consider to Gzip and Base64-encode the query string so that it becomes shorter. Both JavaScript and Java are capable of (de)compressing and (d)e(n)coding it. You can eventually format the query string in JSON before compressing/encoding, it will be shorter in case of arrays/collections/maps. 除了使用一个字母的参数名称(例如?a=value1&b=value2&c=value3或使用类似RESTFul的URL(即仅pathinfo,没有查询参数,例如/value1/value2/value3 ,可以通过HttpServletRequest#getPathInfo() ,而不是?name1=value1&name2=value2&name3=value3 ,您还可以考虑对查询字符串进行Gzip和Base64编码,使其变得更短JavaScript和Java都能够(解压缩)和(d)您可以最终以JSON格式格式化查询字符串,然后再进行压缩/编码,如果是数组/集合/映射,则查询字符串会更短。

That said, are you sure that the request URL's are often that unfriendly long (assuming that it's over 255 characters)? 就是说,您确定请求URL的长度通常不是那么友好(假设超过255个字符)吗? Why would you need to pass that much information in? 您为什么需要传递那么信息? Are they supposed to maintain the client state? 他们应该维护客户端状态吗? If so, you shouldn't use the URL for this, but the HttpSession instance in the server side which is already associated with the jsessionid cooke. 如果是这样,则不应为此使用URL,而应使用服务器端已与jsessionid cooke关联的HttpSession实例。 Use HttpSession#setAttribute() to store some information in session and use HttpSession#getAttribute() to retrieve it. 使用HttpSession#setAttribute()在会话中存储一些信息,并使用HttpSession#getAttribute()检索它。

If you want your application to be security intensive why are you using GET. 如果您希望应用程序的安全性很高,那么为什么要使用GET。 Use POST. 使用POST。 This will also reduce the URL length. 这也将减少URL的长度。

As such, as per the HTTP protocol there is no max length limit to URL length. 因此,根据HTTP协议,URL长度没有最大长度限制。 Most of the time its the browser that puts in the max length limit. 大多数情况下,浏览器会设置最大长度限制。 Try different browsers 尝试不同的浏览器

You should put forward the above points to the interviewer. 您应该向面试官提出以上几点。 They might be more interested in your ability to assess the system as a whole and identify any fundamental flaws. 他们可能对您评估整个系统并确定任何基本缺陷的能力更感兴趣。

If the URL is too long then you have to store that data somewhere else. 如果URL太长,则必须将该数据存储在其他位置。 Most sites would put the session ID in a cookie. 大多数站点会将会话ID放在cookie中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM