Skip to content
This repository was archived by the owner on Nov 19, 2020. It is now read-only.

Commit 1989dc7

Browse files
committed
[NEXUS-8855] resolve relative source against remote URL when checking redirects
1 parent d571319 commit 1989dc7

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

components/nexus-core/src/main/java/org/sonatype/nexus/proxy/storage/remote/httpclient/HttpClientManagerImpl.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,37 +230,55 @@ public boolean isRedirected(final HttpRequest request, final HttpResponse respon
230230
" from proxy " + proxyRepository + " but no location present");
231231
}
232232

233+
final String repoId = proxyRepository.getId();
234+
233235
// Some complication here as it appears that something may be null, but its not clear what was null
234-
final URI sourceUri = ((HttpUriRequest)request).getURI();
236+
URI sourceUri = ((HttpUriRequest) request).getURI();
237+
if (!sourceUri.isAbsolute()) {
238+
try {
239+
sourceUri = URI.create(proxyRepository.getRemoteUrl()).resolve(sourceUri);
240+
}
241+
catch (Exception e) {
242+
logger.debug("[{}] Problem resolving {} against {}", repoId, sourceUri, proxyRepository.getRemoteUrl());
243+
}
244+
}
245+
235246
final String sourceScheme = schemeOf(sourceUri);
236247
final String sourceHost = hostOf(sourceUri);
237248

238249
final URI targetUri = createLocationURI(locationHeader.getValue());
250+
239251
final String targetScheme = schemeOf(targetUri);
240252
final String targetHost = hostOf(targetUri);
241253

254+
final int redirectCode = response.getStatusLine().getStatusCode();
255+
242256
// nag about redirection peculiarities, in any case
243257
if (!Objects.equals(sourceScheme, targetScheme)) {
244258
if ("http".equals(targetScheme)) {
245259
// security risk: HTTPS > HTTP downgrade, you are not safe as you think!
246-
logger.debug("Downgrade from HTTPS to HTTP during redirection {} -> {}", sourceUri, targetUri);
260+
logger.debug("[{}] Downgrade from HTTPS to HTTP during {} redirect {} -> {}",
261+
repoId, redirectCode, sourceUri, targetUri);
247262
}
248263
else if ("https".equals(targetScheme) && Objects.equals(sourceHost, targetHost)) {
249264
// misconfiguration: your repository configured with wrong protocol and causes performance problems?
250-
logger.debug("Protocol upgrade during redirection on same host {} -> {}", sourceUri, targetUri);
265+
logger.debug("[{}] Protocol upgrade during {} redirect on same host {} -> {}",
266+
repoId, redirectCode, sourceUri, targetUri);
251267
}
252268
}
253269

254270
// this logic below should trigger only for content fetches made by RRS retrieveItem
255271
// hence, we do this ONLY if the HttpRequest is "marked" as such request
256272
if (Boolean.TRUE == context.getAttribute(HttpClientRemoteStorage.CONTENT_RETRIEVAL_MARKER_KEY)) {
257273
if (targetUri.getPath().endsWith("/")) {
258-
logger.debug("Not following redirection to index {} -> {}", sourceUri, targetUri);
274+
logger.debug("[{}] Not following {} redirect to index {} -> {}",
275+
repoId, redirectCode, sourceUri, targetUri);
259276
return false;
260277
}
261278
}
262279

263-
logger.debug("Following redirection {} -> {}", sourceUri, targetUri);
280+
logger.debug("[{}] Following {} redirect {} -> {}",
281+
repoId, redirectCode, sourceUri, targetUri);
264282
return true;
265283
}
266284

0 commit comments

Comments
 (0)