File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
src/main/java/org/joychou Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 11package org .joychou .controller ;
2+ import java .util .Arrays ;
3+ import java .util .List ;
24
35import cn .hutool .http .HttpUtil ;
46import org .joychou .security .SecurityUtil ;
Original file line number Diff line number Diff line change 3232 * @author JoyChou 2020-04-06
3333 */
3434public class HttpUtils {
35+ private static final List <String > ALLOWED_URLS = Arrays .asList (
36+ "http://example.com" ,
37+ "http://another-allowed-url.com"
38+ );
39+
40+ private static boolean isValidUrl (String url ) {
41+ try {
42+ URI uri = new URI (url );
43+ return ALLOWED_URLS .contains (uri .getScheme () + "://" + uri .getHost ());
44+ } catch (URISyntaxException e ) {
45+ return false ;
46+ }
47+ }
3548
3649 private final static Logger logger = LoggerFactory .getLogger (HttpUtils .class );
3750
@@ -203,6 +216,9 @@ public static void IOUtils(String url) {
203216
204217
205218 public static String HttpAsyncClients (String url ) {
219+ if (!isValidUrl (url )) {
220+ return "Invalid URL" ;
221+ }
206222 CloseableHttpAsyncClient httpclient = HttpAsyncClients .createDefault ();
207223 try {
208224 httpclient .start ();
You can’t perform that action at this time.
0 commit comments