Files
go-i2ptunnel/lib/irc/client/dcc.go

55 lines
1.6 KiB
Go

package ircclient
/** TODO: implement filters from Java I2P using IRC Filter from go-connfilter.
Java filters copied here:
// DCC command patterns
private static final Pattern DCC_SEND = Pattern.compile("^\\s*DCC\\s+SEND\\s+(\\S+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s*$");
private static final Pattern DCC_CHAT = Pattern.compile("^\\s*DCC\\s+CHAT\\s+chat\\s+(\\d+)\\s+(\\d+)\\s*$");
// Core filtering methods
public String filterDCCRequest(String line) {
// Block direct IP-based DCC
if (line.toUpperCase().startsWith("DCC SEND") ||
line.toUpperCase().startsWith("DCC CHAT")) {
return null;
}
// Filter numeric IPs
if (line.matches(".*\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}.*")) {
return null;
}
return line;
}
// DCC SEND protection
private void handleDCCSend(String filename, String ip, int port, long size) {
// Validate parameters
if (port < 1024 || port > 65535) {
throw new SecurityException("Invalid DCC port");
}
// Block private/local IPs
if (isPrivateIP(ip)) {
throw new SecurityException("Private IP not allowed");
}
}
// DCC CHAT protection
private void handleDCCChat(String ip, int port) {
// Similar port validation
if (port < 1024 || port > 65535) {
throw new SecurityException("Invalid DCC port");
}
}
// IP validation
private boolean isPrivateIP(String ip) {
// Check for private IP ranges
return ip.startsWith("10.") ||
ip.startsWith("172.16.") ||
ip.startsWith("192.168.") ||
ip.equals("127.0.0.1");
}
*/