This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-348bf646-da46-44c3-91bb-6ad02b400f63 XWIKI-24871 Open

A scheduler job can generate URLs based on a previously captured HTTP request instead of the wiki descriptor

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-fb046907-b879-4666-bf8e-2e423e8bce34 Thomas Mortagne created this issue on 14/Sep/26 11:45
 
Summary: A scheduler job can generate URLs based on a previously captured HTTP request instead of the wiki descriptor
Issue Type: cid:jira-generated-image-avatar-348bf646-da46-44c3-91bb-6ad02b400f63 Bug
Affects Versions: 17.10.12
Assignee: Unassigned
Components: Scheduler
Created: 14/Sep/26 11:45
Priority: cid:jira-generated-image-static-major-fe4c4ded-7d08-4348-82ac-de8ea5098f49 Major
Reporter: Thomas Mortagne
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.