2009-06-07 21 views

उत्तर

63

आप इस फ़िल्टर का उपयोग कर केवल खोज इंजन के लिए अक्षम कर सकते हैं, लेकिन मैं सभी प्रतिक्रियाओं के लिए इसका उपयोग कर सलाह देता हूं क्योंकि यह केवल खोज इंजन से भी बदतर है। यह सत्र आईडी का खुलासा करता है जिसका उपयोग कुछ सुरक्षा शोषण (more info) के लिए किया जा सकता है।

बिलाव 6 (पूर्व 6.0.30)

आप tuckey rewrite filter उपयोग कर सकते हैं।

Tuckey फिल्टर के लिए Example config:

<outbound-rule encodefirst="true"> 
    <name>Strip URL Session ID's</name> 
    <from>^(.*?)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$</from> 
    <to>$1$2$3</to> 
</outbound-rule> 

बिलाव 6 (6.0.30 और उसके बाद)

आप संदर्भ विन्यास में disableURLRewriting का उपयोग इस व्यवहार को निष्क्रिय कर सकते हैं।

बिलाव 7 और बिलाव 8

Tomcat 7 onwards से आप सत्र config में निम्नलिखित जोड़ सकते हैं।

<session-config> 
    <tracking-mode>COOKIE</tracking-mode> 
</session-config> 
+6

एक rewriter जब प्रयोग क्यों आनंद लें आप सिर्फ सत्र कुकी नहीं बना सकते हैं? –

+1

कृपया इस उत्तर के लिए तारीख देखें। टॉमकैट 7 और ट्रैकिंग-मोड सुविधा 200 9 में उपलब्ध नहीं थी। अब प्रति संस्करण जानकारी के साथ अपडेट किया गया। – Pool

+0

टॉमकैट 6 कॉन्टेक्स्ट तत्व पर 'disabledURLRewriting' विशेषता का समर्थन करता है जो यह करता है। Http://tomcat.apache.org/tomcat-6.0-doc/config/context.html –

13

वाले सभी URL HttpServletResponseWrapper कि बस यूआरएल encodeRedirectUrl, encodeRedirectURL, encodeUrl और encodeURL से अपरिवर्तित रिटर्न में response लपेटता पर एक Filter का प्रयोग करें। पूल के जवाब से

+3

नमूना कोड यहां उपलब्ध है: http://randomcoder.com/articles/jsessionid-cononsidered-harmful सर्वर डाउन हो सकता है; मुझे इसे Google के कैश से बाहर ले जाना पड़ा। –

+0

मुझे यह दृष्टिकोण पसंद आया। – vsingh

5

उद्धरण:

आप tuckey पुनर्लेखन फिल्टर का उपयोग कर सकते हैं।

सिर्फ इस फिल्टर का उपयोग कर इंजन खोज के लिए अक्षम कर सकते हैं, लेकिन मैं सभी प्रतिक्रियाओं के रूप में यह बदतर बस खोज से इंजन अमित्र है के लिए उपयोग करने सलाह देंगे। यह सत्र आईडी का खुलासा करता है जिसका उपयोग कुछ सुरक्षा शोषण (अधिक जानकारी) के लिए किया जा सकता है।

यह उल्लेखनीय है कि यह अभी भी कुकी आधारित सत्र हैंडलिंग की अनुमति देगा, भले ही jsessionid अब दिखाई नहीं दे रहा है। (अपने अन्य पद से लिया गया: Can I turn off the HttpSession in web.xml?)

पीएस। मेरे पास टिप्पणी करने के लिए पर्याप्त प्रतिष्ठा नहीं है, अन्यथा मैं इसे टिप्पणी के रूप में उपरोक्त पद में जोड़ दूंगा।

2

यदि आपके पास टोमकैट के सामने अपाचे है तो आप एक mod_rewrite फ़िल्टर के साथ jsession को बाहर निकाल सकते हैं।

अपनी अपाचे कॉन्फ़िगरेशन में निम्न जोड़ें।

#Fix up tomcat jsession appending rule issue 
RewriteRule ^/(.*);jsessionid=(.*) /$1 [R=301,L] 

यह एक 301 jsessionid के बिना एक पृष्ठ पर रीडायरेक्ट करेगा। जाहिर है यह पूरी तरह से यूआरएल jsessionid अक्षम कर देगा, लेकिन यह वही है जो मुझे चाहिए।

चीयर्स, मार्क

2

डिफ़ॉल्ट रूप से, कुकीज़ (आप स्पष्ट रूप से कुकीज़ का उपयोग करके इसे सेट कर सकते हैं = server.xml के तत्व में सच) बिलाव सर्वर में सक्षम हैं। कुकीज को सक्षम करने का अर्थ है कि jsessionID को यूआरएल में जोड़ा नहीं जाएगा क्योंकि सत्र कुकीज़ का उपयोग करके प्रबंधित किया जाएगा। हालांकि, कुकीज़ सक्षम होने के बाद भी, jsessionID को पहले अनुरोध के लिए यूआरएल में जोड़ा गया है क्योंकि कुकीज सक्षम होने पर वेबसर्वर उस चरण में नहीं जानता है। इस तरह के jsessionIDs निकालने के लिए आपको tuckey पुनर्लेखन नियमों का उपयोग कर सकते हैं:

आप http://javatechworld.blogspot.com/2011/01/how-to-remove-jsessionid-from-url-java.html

<outbound-rule encodefirst="true"> 
    <note>Remove jsessionid from embedded urls - for urls WITH query parameters</note> 
    <from>^/(.*);jsessionid=.*[?](.*)$</from> 
    <to encode="false">/$1?$2</to> 
</outbound-rule> 

<outbound-rule encodefirst="true"> 
    <note>Remove jsessionid from embedded urls - for urls WITHOUT query parameters</note> 
    <from>^/(.*);jsessionid=.*[^?]$</from> 
    <to encode="false">/$1</to> 
</outbound-rule> 

पर इस बारे में अधिक जानकारी प्राप्त कर सकते हैं आप http://javatechworld.blogspot.com/2011/01/how-to-remove-jsessionid-from-url-java.html

+0

ध्यान दें कि वेबब्रोसर को अभी भी कुकीज़ सक्षम करने की आवश्यकता है। – BalusC

19

पर इस बारे में अधिक जानकारी प्राप्त कर सकते हैं यह करने के लिए संभव है इस बिलाव 6.0 में साथ: disableURLRewriting

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

उदा।

<?xml version='1.0' encoding='utf-8'?> 
<Context docBase="PATH_TO_WEBAPP" path="/CONTEXT" disableURLRewriting="true"> 
</Context> 

बिलाव 7.0 के भीतर, यह एक आवेदन के भीतर निम्नलिखित के साथ नियंत्रित किया जाता है: ServletContext.setSessionTrackingModes()

बिलाव 7.0 सर्वलेट 3.0 विनिर्देशों इस प्रकार है।

51
<session-config> 
    <tracking-mode>COOKIE</tracking-mode> 
</session-config> 

टॉमकैट 7 और टॉमकैट 8 आपके वेब-ऐप web.xml में उपरोक्त कॉन्फ़िगरेशन का समर्थन करते हैं, जो यूआरएल-आधारित सत्रों को अक्षम करता है।

+3

वेब-ऐप_3.0 xsd का उपयोग करना न भूलें: koppor

4

टॉमकैट 6.0 में आप remove.crrriting = "true" का उपयोग कर सकते हैं context.xml में आपके/config पथ से टॉमकैट इंस्टालेशन से।

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

context.xml फ़ाइल

<?xml version='1.0' encoding='utf-8'?> 
<!-- 
    Licensed to the Apache Software Foundation (ASF) under one or more 
    contributor license agreements. See the NOTICE file distributed with 
    this work for additional information regarding copyright ownership. 
    The ASF licenses this file to You under the Apache License, Version 2.0 
    (the "License"); you may not use this file except in compliance with 
    the License. You may obtain a copy of the License at 

     http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, software 
    distributed under the License is distributed on an "AS IS" BASIS, 
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    See the License for the specific language governing permissions and 
    limitations under the License. 
--> 
<!-- The contents of this file will be loaded for each web application --> 
<Context disableURLRewriting="true"> 

    <!-- Default set of monitored resources --> 
    <WatchedResource>WEB-INF/web.xml</WatchedResource> 

    <!-- Uncomment this to disable session persistence across Tomcat restarts --> 
    <!-- 
    <Manager pathname="" /> 
    --> 

    <!-- Uncomment this to enable Comet connection tacking (provides events 
     on session expiration as well as webapp lifecycle) --> 
    <!-- 
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> 
    --> 

</Context> 

...

अब बिल्ला उत्पादन यह अनुकूल खोज इंजन है ...

संबंधित मुद्दे