Skip to content

Commit

Permalink
Reinstate permissive alias check
Browse files Browse the repository at this point in the history
Without the permissive check, unusually named static resources are
inaccessible. The need for this may be due to a Jetty bug. This change
restores the tests to their previous form for now.

See spring-projectsgh-40568
  • Loading branch information
wilkinsona committed Apr 29, 2024
1 parent f70a270 commit 34e62bb
Showing 1 changed file with 7 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
import org.eclipse.jetty.server.AllowedResourceAliasChecker;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.handler.ContextHandler;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
Expand All @@ -29,19 +30,23 @@
/**
* {@link JettyServerCustomizer} that:
* <ul>
* <li>Approves all aliases to allow access to unusually named static resources
* <li>Relaxes URI compliance to allow access to static resources with {@code %} in their file name.
* </ul>
*
* @author Madhura Bhave
* @author Andy Wilkinson
*/
@ConditionalOnClass(name = "org.eclipse.jetty.server.Connector")
@ConditionalOnClass(name = {"org.eclipse.jetty.server.handler.ContextHandler"})
@Configuration(proxyBeanMethods = false)
public class JettyServerCustomizerConfig {

@Bean
public JettyServerCustomizer jettyServerCustomizer() {
return (server) -> {
ContextHandler handler = (ContextHandler) server.getHandler();
handler.addAliasCheck((path, resource) -> true);

for (Connector connector : server.getConnectors()) {
connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration()
.setUriCompliance(UriCompliance.LEGACY);
Expand Down

0 comments on commit 34e62bb

Please sign in to comment.