When Using Clientless Access (CVPN), Some URLs Referenced in External JavaScript File are Not Rewritten Appropriately

When Using Clientless Access (CVPN), Some URLs Referenced in External JavaScript File are Not Rewritten Appropriately

book

Article ID: CTX122984

calendar_today

Updated On:

Description

When using Clientless access, some URLs referenced in the external JavaScript files are not rewritten appropriately.

Resolution

To resolve this issue, you can implement any of the following solutions:

Solution 1

The recommended solution is to assign appropriate MIME-type for the file extension on the back end server. This article contains information about assigning appropriate MIME-type on a Microsoft Internet Information Services, as shown in the following screen shot:

User-added image

Note: If another web server is used, refer to the web server documentation to assign appropriate MIME-type to the file extension.

When the header traces are examined after making the preceding changes, the appropriate Content-Type is assigned to the .js file, as shown in the following screen shot:

User-added image

Additionally, the URLs in the JavaScript are rewritten appropriately, as shown in the following content of the javascriptTest.js JavaScript file:

// *****************************************************
// * Portal Clientless Javascript testing *
// *****************************************************
function relativeImageDoubleQuotes() {
document.write("<IMG SRC=\"images/blue.jpg\">");
}
function absoluteImageDoubleQuotes() {
document.write("<IMG SRC=\"https://agee.dj.ctx/cvpn/http/172.16.100.8:8080/test_javascript/images/blue.jpg\">");
}

When the user accesses the web page, the appropriate content is displayed on the browser, as shown in the following screen shot:

User-added image

Solution 2

At times, the NetScaler administrator does not have control over the back end servers. In such cases, changing the MIME-type on the back end server might not be possible. To address the issue and enable the Clientless Virtual Private Network (CVPN) engine to parse the HTML and JavaScript content appropriately, you can use the global rewrite policy of the NetScaler appliance. The following is a sample action and policy to enable the CVPN engine on the NetScaler appliance to parse the HTML and JavaScript content appropriately:

add rewrite action ReplaceContentTypeHeader replace "HTTP.RES.HEADER(\"Content-Type\")" "\"application/x-javascript\""
add rewrite policy ReplaceContentTypeForJS "HTTP.REQ.URL.CONTAINS(\".js\")" ReplaceContentTypeHeader
bind rewrite global ReplaceContentTypeForJS 100 END -type RES_OVERRIDE

User-added image

Additionally, when the user accesses the web page, the appropriate content is displayed on the browser, as shown in the following screen shot:

User-added image

Disclaimer

This article is provided as is, and while it might help you troubleshoot your specific application, Citrix Technical Support can only use best efforts to provide support for customized applications. Outlook Web Access and SharePoint are the only fully supported applications for which specific rewrite policies have been created when using Clientless mode.


Problem Cause

When the incorrect Content-Type header is assigned, the CVPN engine does not parse the URL appropriately and the engine is unable to rewrite the URL.

Issue/Introduction

When using clientless access, some URLs referenced in the external JavaScript files are not rewritten appropriately.

Additional Information

Troubleshooting Methodology

  • The following is a sample HTML source to explain the concept:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Clientless Testing Page 2</title>
    
    <script type="text/javascript" src="javascriptTest.js"></script>
    </head>
    <body>
    <h1>Javascript Testing - JS in separate file</h1>
    <!-- Double Quotes Break With default Clientless Access -->
    <p>Double Quote Relative Link Here -> <script language="javascript" type="text/javascript">relativeImageDoubleQuotes();</script></p>
    <p>Double Quote Absolute Link Here -> <script language="javascript" type="text/javascript">absoluteImageDoubleQuotes();</script></p>
    </body>
    </html>
  • The following is the content of the JavaScript file, javascriptTest.js, referenced in the preceding HTML source:

    // *****************************************************
    // * Portal Clientless Javascript testing      *
    // *****************************************************
    function relativeImageDoubleQuotes() {
         document.write("<IMG SRC=\"images/blue.jpg\">");
    }
    function absoluteImageDoubleQuotes() {
         document.write("<IMG SRC=\"http://172.16.100.8:8080/test_javascript/images/blue.jpg\">");
    }
    
  • When header traces are recorded on the client computer while attempting to browse the content, the traces contain incorrect Content-Type assigned to the .js files, which is done deliberately, as shown in the following screen shot:

    User-added image

  • Even though the incorrect header value is assigned, all major browsers display the content without any issues when browsing the site directly, as shown in the following screen shot:

    User-added image

  • However, when publishing this content from the Access Gateway Enterprise Edition CVPN, the incorrect Content-Type confuses the CVPN engine and the URL is parsed incorrectly, as shown in the header traces in the following screen shot:

    User-added image

  • If you examine the JavaScript source, you can notice how the CVPN engine parses the URL incorrectly, breaking the site. This is highlighted in bold in the following content of the javascriptTest.js JavaScript file:

    // *****************************************************
    // * Portal Clientless Javascript testing *
    // *****************************************************
    function relativeImageDoubleQuotes() {
    document.write("<IMG SRC=\cvpn\http\172.16.100.8:8080\"images/blue.jpg\">");
    }
    function absoluteImageDoubleQuotes() {
    document.write("<IMG SRC=\cvpn\http\172.16.100.8:8080\"http://172.16.100.8:8080/test_javascript/images/blue.jpg\">");
    }
  • The following screen shot displays the broken link when the web page is browsed from the Access Gateway Enterprise Edition CVPN:

    User-added image