Skip to content

Commit c5d401d

Browse files
author
sahilleth
committed
Fix newView link to use context-relative URL instead of rootURL
Fixes JENKINS-51291 / #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. Made-with: Cursor
1 parent 057aa6a commit c5d401d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

core/src/main/resources/hudson/views/DefaultMyViewsTabBar/myViewTabs.jelly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ THE SOFTWARE.
3030
<l:tab name="${v.displayName}" active="${v==currentView}" href="${rootURL}/${v.url}" />
3131
</j:forEach>
3232
<j:if test="${currentView.hasPermission(currentView.CREATE)}">
33-
<l:tabNewItem href="${rootURL}/${currentView.owner.url}newView" title="${%New View}" />
33+
<l:tabNewItem href="${request.contextPath}/${currentView.owner.url}newView" title="${%New View}" />
3434
</j:if>
3535
</l:tabBar>
3636
</j:jelly>

core/src/main/resources/hudson/views/DefaultViewsTabBar/viewTabs.jelly

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ THE SOFTWARE.
4141
</j:forEach>
4242

4343
<j:if test="${currentView.hasPermission(currentView.CREATE)}">
44-
<a href="${rootURL}/${currentView.owner.url}newView" tooltip="${%New View}" class="jenkins-button jenkins-button--tertiary">
44+
<a href="${request.contextPath}/${currentView.owner.url}newView" tooltip="${%New View}" class="jenkins-button jenkins-button--tertiary">
4545
<l:icon src="symbol-add" />
4646
</a>
4747
</j:if>
@@ -53,7 +53,7 @@ THE SOFTWARE.
5353
<l:tab name="${v.displayName}" active="${v==currentView}" href="${rootURL}/${v.url}" />
5454
</j:forEach>
5555
<j:if test="${currentView.hasPermission(currentView.CREATE)}">
56-
<l:tabNewItem href="${rootURL}/${currentView.owner.url}newView" title="${%New View}" />
56+
<l:tabNewItem href="${request.contextPath}/${currentView.owner.url}newView" title="${%New View}" />
5757
</j:if>
5858
</l:tabBar>
5959
</j:otherwise>

0 commit comments

Comments
 (0)