how can I clean and sanitize a url submitted by a user for redisplay in java?

后端 未结 3 1555
孤街浪徒
孤街浪徒 2021-01-23 02:43

I want a user to be able to submit a url, and then display that url to other users as a link.

If I naively redisplay what the user submitted, I leave myself open to urls

3条回答
  •  自闭症患者
    2021-01-23 03:23

    You can use apache validator URLValidator

    UrlValidator urlValidator = new UrlValidator(schemes);
    if (urlValidator.isValid("http://somesite.com")) {
       //valid
    }
    

提交回复
热议问题