Repository: Stirling-Tools/Stirling-PDF
File: app/proprietary/src/main/java/stirling/software/proprietary/security/filter/EnterpriseEndpointFilter.java (Java)

Code before:
    private final boolean runningProOrHigher;

    public EnterpriseEndpointFilter(@Qualifier("runningProOrHigher") boolean runningProOrHigher) {
        this.runningProOrHigher = runningProOrHigher;
    }

    @Override
    protected void doFilterInternal(
            HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {

        if (!runningProOrHigher && isPrometheusEndpointRequest(request)) {
            // Allow only health checks to pass through for non-pro users
            String uri = request.getRequestURI();

            // Strip the context path
            String contextPath = request.getContextPath();
            String trimmedUri =
                    (contextPath != null && uri.startsWith(contextPath))
                            ? uri.substring(contextPath.length())
                            : uri;

            boolean isHealthCheck =
                    trimmedUri.startsWith("/actuator/health")
                            || "/healthz".equals(trimmedUri)
                            || "/liveness".equals(trimmedUri)
                            || "/readiness".equals(trimmedUri);

            if (!isHealthCheck) {
                response.setStatus(HttpStatus.NOT_FOUND.value());
                return;
            }
        }
        filterChain.doFilter(request, response);
    }

    private boolean isPrometheusEndpointRequest(HttpServletRequest request) {
        return request.getRequestURI().contains("/actuator/");
    }
}


Review comment (suggestion):
Can you add `/health` here too for consistency?
```suggestion
                            || "/health".equals(trimmedUri)
                            || "/healthz".equals(trimmedUri)
```

Code after:
    private final boolean runningProOrHigher;

    public EnterpriseEndpointFilter(@Qualifier("runningProOrHigher") boolean runningProOrHigher) {
        this.runningProOrHigher = runningProOrHigher;
    }

    @Override
    protected void doFilterInternal(
            HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {

        if (!runningProOrHigher && isPrometheusEndpointRequest(request)) {
            // Allow only health checks to pass through for non-pro users
            String uri = request.getRequestURI();

            // Strip the context path
            String contextPath = request.getContextPath();
            String trimmedUri =
                    (contextPath != null && uri.startsWith(contextPath))
                            ? uri.substring(contextPath.length())
                            : uri;

            boolean isHealthCheck =
                    trimmedUri.startsWith("/actuator/health")
                            || "/health".equals(trimmedUri)
                            || "/healthz".equals(trimmedUri)
                            || "/liveness".equals(trimmedUri)
                            || "/readiness".equals(trimmedUri);

            if (!isHealthCheck) {
                response.setStatus(HttpStatus.NOT_FOUND.value());
                return;
            }
        }
        filterChain.doFilter(request, response);
    }

    private boolean isPrometheusEndpointRequest(HttpServletRequest request) {
        return request.getRequestURI().contains("/actuator/");
    }
}