Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-227

XWiki generates wrong links behind a reverse proxy with https

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Minor
    • None
    • 1.0 B1
    • None
    • Tomcat 5.5.16 JDK 1.5.0_06-b05, Apache/2.0.55 with mod_proxy on Linux

    Description

      When running behind a reverse proxy using https (e.g. https://secure.domain.com/xwiki/bin/view/Main/) the links are not prefixed with https but with http. The reason is the XWikiServletURLFactory.getServerURL evaluating the x-forwarded-host header of mod_proxy.

      Fix:

      • a) add a second header to specify the scheme
      • b) add a configuration flag to disable evaluation of the x-forwarded-host header (but I don't know what this will break)

      I've tested and implemented a):

      • add this line to apache vhost config:
        RequestHeader set X-Request-Scheme https
      • apply this patch to the XWikiServeltURLFactory
      ===================================================================
      --- src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java (revision 975)
      +++ src/main/java/com/xpn/xwiki/web/XWikiServletURLFactory.java (working copy)
      @@ -101,10 +101,13 @@
                   if (host!=null) {            
                      int comaind = host.indexOf(',');
                      final String host1 = comaind>0 ? host.substring(0, comaind) : host;
      -               if (!host1.equals(""))
      -                       return new URL("http://"+host1);
      +               if (!host1.equals("")) {
      +                       String scheme = context.getRequest().getHeader("x-request-scheme");
      +                       scheme = scheme == null ? "http" : scheme;
      +                       return new URL(scheme + "://"+host1);
      +               }
                   }
      -        }
      +        } 
               if (xwikidb==null)
                   return serverURL;
      

      Attachments

        Issue Links

          Activity

            People

              mflorea Marius Dumitru Florea
              next2you Christian van der Leeden
              Votes:
              4 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: