Skip to content

Commit

Permalink
Judge null for key and value in attachment in RpcContextFilter.
Browse files Browse the repository at this point in the history
  • Loading branch information
carryxyh committed Jul 27, 2018
1 parent e90d95c commit 8d962bf
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.RpcContext;

import org.jboss.resteasy.spi.ResteasyProviderFactory;

import javax.annotation.Priority;
Expand Down Expand Up @@ -70,9 +69,17 @@ public void filter(ContainerRequestContext requestContext) throws IOException {
public void filter(ClientRequestContext requestContext) throws IOException {
int size = 0;
for (Map.Entry<String, String> entry : RpcContext.getContext().getAttachments().entrySet()) {
if (entry.getValue().contains(",") || entry.getValue().contains("=")
|| entry.getKey().contains(",") || entry.getKey().contains("=")) {
throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " must not contain ',' or '=' when using rest protocol");
String key = entry.getKey();
String value = entry.getValue();
if (StringUtils.isNotEmpty(key)) {
if (illegalForRest(key)) {
throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " must not contain ',' or '=' when using rest protocol");
}
}
if (StringUtils.isNotEmpty(value)) {
if (illegalForRest(value)) {
throw new IllegalArgumentException("The attachments of " + RpcContext.class.getSimpleName() + " must not contain ',' or '=' when using rest protocol");
}
}

// TODO for now we don't consider the differences of encoding and server limit
Expand All @@ -85,4 +92,14 @@ public void filter(ClientRequestContext requestContext) throws IOException {
requestContext.getHeaders().add(DUBBO_ATTACHMENT_HEADER, attachments);
}
}

/**
* If a string value illegal for rest protocol(',' and '=' is illegal for rest protocol).
*
* @param v string value
* @return true for illegal
*/
private boolean illegalForRest(String v) {
return v.contains(",") || v.contains("=");
}
}

0 comments on commit 8d962bf

Please sign in to comment.