Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.apache.cxf.message.Attachment;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.resource.URIResolver;

public final class AttachmentUtil {
// The default values for {@link AttachmentDataSource} content type in case when
Expand Down Expand Up @@ -593,12 +594,16 @@
final boolean followUrls = Boolean.valueOf(SystemPropertyAction
.getProperty(ATTACHMENT_XOP_FOLLOW_URLS_PROPERTY, "false"));
if (followUrls) {
return new URLDataSource(new URL(contentId));
final URL remoteUrl = new URL(contentId);
URIResolver.checkAllowedScheme(remoteUrl);
return new URLDataSource(remoteUrl);

Check failure

Code scanning / CodeQL

Server-side request forgery Critical

Potential server-side request forgery due to a
user-provided value
.
Potential server-side request forgery due to a
user-provided value
.
Potential server-side request forgery due to a
user-provided value
.
Potential server-side request forgery due to a
user-provided value
.
Comment thread
coheigea marked this conversation as resolved.
Dismissed
} else {
return loadDataSource(contentId, atts);
}
} catch (MalformedURLException e) {
throw new Fault(e);
} catch (IOException e) {
throw new Fault(e);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import jakarta.activation.DataSource;
import jakarta.activation.URLDataSource;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.io.CacheSizeExceededException;
import org.apache.cxf.message.Attachment;
import org.apache.cxf.message.Exchange;
Expand Down Expand Up @@ -942,4 +943,15 @@ public void testCXF8706followUrl() {
System.clearProperty(AttachmentUtil.ATTACHMENT_XOP_FOLLOW_URLS_PROPERTY);
}
}

@Test
public void testCXF8706followUrlRejectsDisallowedScheme() {
System.setProperty(AttachmentUtil.ATTACHMENT_XOP_FOLLOW_URLS_PROPERTY, "true");
try {
assertThrows(Fault.class, () -> AttachmentUtil
.getAttachmentDataSource("cid:gopher://image.com/1.gif", Collections.emptyList()));
} finally {
System.clearProperty(AttachmentUtil.ATTACHMENT_XOP_FOLLOW_URLS_PROPERTY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.cxf.aegis.type.mtom;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
Expand All @@ -32,6 +31,7 @@
import org.apache.cxf.attachment.AttachmentImpl;
import org.apache.cxf.common.util.SystemPropertyAction;
import org.apache.cxf.message.Attachment;
import org.apache.cxf.resource.URIResolver;

public final class AttachmentUtil {
// The xop:include "href" attribute (https://www.w3.org/TR/xop10/#xop_href) may include
Expand Down Expand Up @@ -78,9 +78,11 @@ public static Attachment getAttachment(String id, Collection<Attachment> attachm
if (followUrls) {
// Try loading the URL remotely
try {
URLDataSource source = new URLDataSource(new URL(id));
final URL remoteUrl = new URL(id);
URIResolver.checkAllowedScheme(remoteUrl);
URLDataSource source = new URLDataSource(remoteUrl);
return new AttachmentImpl(id, new DataHandler(source));
} catch (MalformedURLException e) {
} catch (java.io.IOException e) {
return null;
}
}
Expand Down
Loading