Skip to content

Commit

Permalink
Mitigate possible injection attack
Browse files Browse the repository at this point in the history
  • Loading branch information
tboeghk committed Jan 7, 2025
1 parent 08e5507 commit 3d5c2e7
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@

import java.beans.PropertyEditorSupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.net.InetAddresses;

import static com.google.common.base.Preconditions.checkNotNull;

public class InetAdressPropertyEditor extends PropertyEditorSupport {

private final Logger logger = LoggerFactory.getLogger(getClass());

@Override
public void setAsText(String text) {
checkNotNull(text, "Pre-condition violated: text must not be null.");

try {
setValue(InetAddresses.forString(text));
} catch (IllegalArgumentException e) {
throw new InvalidIpAddressException(e.getMessage());
logger.info("Invalid IP address given: {}", e.getMessage());
throw new InvalidIpAddressException("Invalid IP address given");
}
}
}

0 comments on commit 3d5c2e7

Please sign in to comment.