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

Resolved Bypass Issue in 'refresh' Command Route for URL Restricted List #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions common/src/main/java/com/loohp/imageframe/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,10 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
}
}
}
if (!ImageFrame.isURLAllowed(url)) {
sender.sendMessage(ImageFrame.messageURLRestricted);
return;
}
if (imageMap == null) {
if (!(sender instanceof Player)) {
sender.sendMessage(ImageFrame.messageNoConsole);
Expand Down
39 changes: 27 additions & 12 deletions common/src/main/java/com/loohp/imageframe/ImageFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
import javax.imageio.spi.IIORegistry;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -174,20 +176,33 @@ public class ImageFrame extends JavaPlugin {
public static boolean isURLAllowed(String link) {
if (!restrictImageUrlEnabled) {
return true;
}
try {
URL url = new URL(link);
return restrictImageUrls.stream().anyMatch(whitelisted -> {
if (!url.getProtocol().equalsIgnoreCase(whitelisted.getProtocol())) {
return false;
}
if (!url.getHost().equalsIgnoreCase(whitelisted.getHost())) {
} else {
try {
URL url = new URL(link);
String linkHost = url.getHost();

InetAddress linkAddress;
try {
linkAddress = InetAddress.getByName(linkHost);
} catch (UnknownHostException var5) {
return false;
}
return url.getPath().toLowerCase().startsWith(whitelisted.getPath().toLowerCase());
});
} catch (MalformedURLException e) {
return false;

return restrictImageUrls.stream().anyMatch((whitelisted) -> {
try {
if (!url.getProtocol().equalsIgnoreCase(whitelisted.getProtocol())) {
return false;
} else {
InetAddress whitelistAddress = InetAddress.getByName(whitelisted.getHost());
return linkAddress.equals(whitelistAddress) && url.getPath().toLowerCase().startsWith(whitelisted.getPath().toLowerCase());
}
} catch (UnknownHostException var4) {
return false;
}
});
} catch (MalformedURLException var6) {
return false;
}
}
}

Expand Down