fix(http): enable restricted headers for DNS rebinding protection and improve host header handling (#3022)
This commit is contained in:
@@ -14,6 +14,10 @@ import org.booklore.config.BookmarkProperties;
|
||||
@SpringBootApplication
|
||||
public class BookloreApplication {
|
||||
|
||||
static {
|
||||
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BookloreApplication.class, args);
|
||||
}
|
||||
|
||||
@@ -262,8 +262,11 @@ public class SecurityConfig {
|
||||
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
|
||||
super.prepareConnection(connection, httpMethod);
|
||||
connection.setInstanceFollowRedirects(false);
|
||||
String targetHost = FileService.getTargetHost();
|
||||
if (targetHost != null) {
|
||||
connection.setRequestProperty("Host", targetHost);
|
||||
}
|
||||
if (connection instanceof HttpsURLConnection httpsConnection) {
|
||||
String targetHost = FileService.getTargetHost();
|
||||
if (targetHost != null) {
|
||||
// Set original host for SNI (even if connecting to IP)
|
||||
SSLSocketFactory defaultFactory = httpsConnection.getSSLSocketFactory();
|
||||
|
||||
@@ -57,11 +57,6 @@ public class FileService {
|
||||
TARGET_HOST_THREAD_LOCAL.remove();
|
||||
}
|
||||
|
||||
static {
|
||||
// Enable restricted headers to allow 'Host' header override for DNS rebinding protection
|
||||
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
|
||||
}
|
||||
|
||||
private final AppProperties appProperties;
|
||||
private final RestTemplate restTemplate;
|
||||
private final AppSettingService appSettingService;
|
||||
|
||||
Reference in New Issue
Block a user