Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
17.10.12
-
None
-
Unknown
-
Description
URLs generated inside a Groovy scheduler job (and the mails such a job sends) can use the host of some HTTP request captured earlier by the instance, instead of the current wiki descriptor. On an instance behind a reverse proxy passing its own internal Host (Host: xwiki), a weekly report job produced links like http://xwiki/xwiki/bin/view/... while the main wiki descriptor correctly declares xwiki.atelier-medias.org with SSL enabled, and xwiki.home is not set.
XWikiServletURLFactory.init only consults the trusted XWiki#getServerURL (i.e. xwiki.home, then the wiki descriptor) when the context request is a stub flagged as daemon; otherwise it pins the base URL to HttpServletUtils.getSourceBaseURL(request). SchedulerPlugin#prepareJobStubContext builds the job context request with new XWikiServletRequestStub(context.getRequest()), which keeps the daemon flag of the source when the source is itself a stub. So when a job happens to be scheduled from a context restored by RequestInitializer with a stored request URL (daemon set to false there), the scheduled job inherits a non-daemon request and every URL it generates is based on that captured request for the lifetime of the schedule.
A Quartz-scheduled job is by definition a long-running daemon context with no current request, so it should never take a captured request into account when generating URLs, whatever context it was scheduled from.
Proposed fix: force the flag in SchedulerPlugin#prepareJobStubContext, right after the stub is created:
XWikiServletRequestStub dummy = new XWikiServletRequestStub(context.getRequest()); // A scheduled job is a daemon context: URLs must be generated from the wiki descriptor, not from // the request that happened to be current when the job was scheduled. dummy.setDaemon(true);
The same reasoning arguably applies to DefaultXWikiStubContextProvider#createStubContext().
Workaround: set xwiki.home in xwiki.cfg (it takes precedence for the main wiki whatever the daemon mode), or set the flag from the job script itself before generating any URL.