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

Added validations for fixing SSRF #1417

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion src/main/java/com/flightstats/hub/channel/ProviderResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.regex.Pattern;

/**
* This is a convenience interface for external data Providers.
Expand All @@ -28,6 +30,8 @@
@Path("/provider")
public class ProviderResource {

private static final Pattern CHANNEL_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9_-]+$");
private static final String ALLOWED_CONTENT_TYPES = "application/hub";
private final ChannelService channelService;
private final ContentRetriever contentRetriever;

Expand Down Expand Up @@ -80,10 +84,21 @@ public Response insertValue(@HeaderParam("channelName") final String channelName
@Path("/bulk")
public Response insertBulk(@HeaderParam("channelName") final String channelName,
@HeaderParam("Content-Type") final String contentType,
final InputStream data) {
final InputStream data) throws IOException {
try {

ensureChannel(channelName);

// Validate channelName
if (channelName == null || !CHANNEL_NAME_PATTERN.matcher(channelName).matches()) {
return Response.status(400).entity("Invalid channel name").build();
}

// Validate contentType
if (contentType == null || !ALLOWED_CONTENT_TYPES.contains(contentType)) {
return Response.status(400).entity("Invalid content type").build();
}

BulkContent content = BulkContent.builder()
.isNew(true)
.contentType(contentType)
Expand Down