Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EndpointRequest.toLinks() does not match when management.endpoints.web.base-path is '/' #34834

Open
nightswimmings opened this issue Apr 1, 2023 · 4 comments
Labels
type: bug A general bug
Milestone

Comments

@nightswimmings
Copy link

nightswimmings commented Apr 1, 2023

I am using a different management port with management.server.base-path: '/management' and management.endpoints.web.base-path: '/'.

When setting up security as .requestMatchers(EndpointRequest.toLinks()).permitAll(), then performing a request over '/management/', returns 403

Root cause:
WebEndpointProperties.setBasePath cleans '/' as ''.

Later on, upon first '/' call, LinksRequestMatcher sees the empty basepath and returns EndpointRequest.EMPTY_MATCHER, which always evaluates to false

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 1, 2023
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 28, 2023
@wilkinsona wilkinsona added this to the 2.7.x milestone Apr 28, 2023
@somayaj
Copy link
Contributor

somayaj commented May 22, 2023

@philwebb
Copy link
Member

@somayaj You're welcome to work on the issue, I'll assign it to you. Ideally we'll be looking to add a test as well.

somayaj added a commit to somayaj/spring-boot that referenced this issue May 22, 2023
@mhalbritter mhalbritter closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2023
@mhalbritter mhalbritter reopened this May 23, 2023
somayaj added a commit to somayaj/spring-boot that referenced this issue May 23, 2023
@wilkinsona
Copy link
Member

This is deceptively complicated as EndpointRequest.toLinks() needs to return different matchers depending on whether or not actuator is running on a separate port.

@somayaj
Copy link
Contributor

somayaj commented Sep 16, 2023

@wilkinsona not sure if this would make sense or would be in the right direction?
public static final class LinksRequestMatcher extends AbstractRequestMatcher {

	@Override
	protected RequestMatcher createDelegate(WebApplicationContext context,
			RequestMatcherFactory requestMatcherFactory) {
		WebEndpointProperties properties = context.getBean(WebEndpointProperties.class);
		String basePath = properties.getBasePath();
		ManagementPortType port = ManagementPortType.get(context.getEnvironment());
		if (StringUtils.hasText(basePath) && !(port == ManagementPortType.DIFFERENT )) {
			return new OrRequestMatcher(
					getLinksMatchers(requestMatcherFactory, getRequestMatcherProvider(context), basePath));
		}
		else if(port == ManagementPortType.DIFFERENT) {
			return new OrRequestMatcher(
					getLinksMatchers(requestMatcherFactory, getRequestMatcherProvider(context), properties.getBasePath())); // not sure what to put here yet? 
		}

		return EMPTY_MATCHER;
	}

}

@philwebb philwebb modified the milestones: 2.7.x, 3.1.x Nov 8, 2023
@wilkinsona wilkinsona modified the milestones: 3.1.x, 3.2.x May 20, 2024
@philwebb philwebb modified the milestones: 3.2.x, 3.3.x Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
6 participants