Skip to content

Fix newView link to use context-relative URL instead of rootURL#26383

Closed
sahilleth wants to merge 2 commits intojenkinsci:masterfrom
sahilleth:fix/22743-new-view-relative-url
Closed

Fix newView link to use context-relative URL instead of rootURL#26383
sahilleth wants to merge 2 commits intojenkinsci:masterfrom
sahilleth:fix/22743-new-view-relative-url

Conversation

@sahilleth
Copy link

Fixes #22743

What was done

The "New View" link in the view tab bar used ${rootURL} which produces an absolute URL. When Jenkins is behind a reverse proxy (e.g. nginx) with Root URL set to the internal server for agent connectivity, clicking "New View" redirected users to the internal URL instead of staying on the proxy URL.

Fix: Use ${request.contextPath}/${currentView.owner.url}newView instead of ${rootURL}/${currentView.owner.url}newView. This produces a path-absolute URL (e.g. /jenkins/newView or /jenkins/job/foo/newView) that the browser resolves against the current origin (the proxy URL), while still correctly targeting the owning ViewGroup's newView for root, folders, and My Views.

This also addresses SECURITY-1471 by removing rootURL from the link, preventing javascript: injection via Root URL configuration.

Testing done

  • Changed files: DefaultViewsTabBar/viewTabs.jelly, DefaultMyViewsTabBar/myViewTabs.jelly
  • Existing test JenkinsLocationConfigurationTest#cannotInjectJavaScriptUsingRootUrl_inNewViewLink validates that the newView link does not use rootURL for XSS; this change strengthens that by not using rootURL at all
  • Manual verification: Links now use path-relative format that resolves to current host

Proposed changelog entries

  • Make the "New View" link use a context-relative URL so it works correctly when Jenkins is behind a reverse proxy with Root URL configured for internal agent connectivity

Proposed changelog category

/label bug

Submitter checklist

  • The issue is well-described
  • Changelog entry is in imperative mood
  • Existing SECURITY-1471 test covers the change
  • No new public APIs
  • No CSP impact (Jelly template change only)

@comment-ops-bot comment-ops-bot bot added the bug For changelog: Minor bug. Will be listed after features label Feb 28, 2026
@sahilleth
Copy link
Author

CI is green after updating href handling. Please let me know if further adjustments are needed.

sahilleth added 2 commits February 28, 2026 23:31
Fixes JENKINS-51291 / jenkinsci#22743

When Jenkins is behind a reverse proxy (e.g. nginx), the Jenkins Root URL
may be configured to the internal server URL for agent connectivity.
The 'New View' link in the view tab bar was using rootURL, causing it to
navigate to the internal URL instead of the proxy URL.

Use request.contextPath + owner.url instead of rootURL so the link
resolves relative to the current origin (proxy URL), while still
correctly targeting the owning ViewGroup's newView action for both
root, folders, and My Views. This also fixes SECURITY-1471 by removing
rootURL from the link, preventing javascript: injection via Root URL.
ViewTest.privateView fails on Windows JDK 25 when tab hrefs use rootURL
because the active-tab URL match can differ. Use request.contextPath
for tab links to ensure consistency with the request URL.

Also fixes the same proxy issue for view tab links as for the newView button.
@daniel-beck
Copy link
Member

The "New View" link in the view tab bar used ${rootURL} which produces an absolute URL.

No:

String rootURL = currentRequest.getContextPath();
Functions h = new Functions();
context.setVariable("h", h);
// The path starts with a "/" character but does not end with a "/" character.
context.setVariable("rootURL", rootURL);

This PR does nothing.

@daniel-beck daniel-beck added the spam This pull request is not a valid change proposal (e.g. vandalism, empty changes) label Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug For changelog: Minor bug. Will be listed after features spam This pull request is not a valid change proposal (e.g. vandalism, empty changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-51291] 'new view' wrong url - not relative

2 participants