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

Recommendation for securing /monitoring while allowing access to boomerang.js #1224

Open
danshome opened this issue May 22, 2024 · 2 comments

Comments

@danshome
Copy link

I'm trying to find recommendations for securing /monitoring while still allowing access to the URL parameter /monitoring?resource=boomerang.min.js. The documentation doesn't discuss this.

@evernat
Copy link
Member

evernat commented May 25, 2024

If you use the authorized-users or allowed-addr-pattern javamelody parameters for securing /monitoring, then you have nothing more to do : javamelody restricts access to /monitoring and already allows access to /monitoring?resource=boomerang.min.js.

If you use security-constraint in web.xml for securing /monitoring, I do not think that there is a solution to allow access to /monitoring?resource=boomerang.min.js.

If you use spring-security for securing /monitoring for example with the javamelody-spring-boot-starter, then you can secure /monitoring and allow access to /monitoring?resource=boomerang.min.js using a custom request matcher, that is something like:

@Configuration
@EnableWebSecurity
public class WebSecurityConfig {

	@Bean
	public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
		http
			.authorizeHttpRequests(requests -> requests
				// custom request matcher to allow access to /monitoring?resource=boomerang.min.js
				.requestMatchers(request ->
					request.getRequestURI().equals(request.getContextPath() + "/monitoring")
					&& "boomerang.min.js".equals(request.getParameter("resource"))
				).permitAll()
				// request matcher to secure access to /monitoring
				.requestMatchers("/monitoring").hasAuthority("ROLE_MONITORING")
				// anything else as you want
				.anyRequest().authenticated()
			)
			...;

		return http.build();
	}
}

@evernat
Copy link
Member

evernat commented May 25, 2024

Of course, you need access to boomerang.min.js only if you use the Real User Monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants