Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable URLDataSource by default for Aegis #1727

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@
import org.apache.cxf.aegis.DatabindingException;
import org.apache.cxf.aegis.util.UID;
import org.apache.cxf.attachment.AttachmentImpl;
import org.apache.cxf.common.util.SystemPropertyAction;
import org.apache.cxf.message.Attachment;

public final class AttachmentUtil {
// The xop:include "href" attribute (https://www.w3.org/TR/xop10/#xop_href) may include
// arbitrary URL which we should never follow (unless explicitly allowed).
public static final String ATTACHMENT_XOP_FOLLOW_URLS_PROPERTY = "org.apache.cxf.attachment.xop.follow.urls";

private AttachmentUtil() {
//utility class
}
Expand All @@ -51,28 +56,34 @@ public static Attachment getAttachment(String id, Collection<Attachment> attachm
if (id == null) {
throw new DatabindingException("Cannot get attachment: null id");
}
if (attachments == null) {
return null;
}


int i = id.indexOf("cid:");
if (i != -1) {
id = id.substring(4).trim();
}

if (attachments == null) {
return null;
}

for (Iterator<Attachment> iter = attachments.iterator(); iter.hasNext();) {
Attachment a = iter.next();
if (a.getId().equals(id)) {
return a;
}
}

// Try loading the URL remotely
try {
URLDataSource source = new URLDataSource(new URL(id));
return new AttachmentImpl(id, new DataHandler(source));
} catch (MalformedURLException e) {
return null;
final boolean followUrls = Boolean.valueOf(SystemPropertyAction
.getProperty(ATTACHMENT_XOP_FOLLOW_URLS_PROPERTY, "false"));
if (followUrls) {
// Try loading the URL remotely
try {
URLDataSource source = new URLDataSource(new URL(id));
return new AttachmentImpl(id, new DataHandler(source));
} catch (MalformedURLException e) {
return null;
}
}
return null;
}
}