php - XSS with javascript:alert() - Stack Overflow

I'm working on some Reflected Cross-site scripting (XSS) vulnerabilities on our site (php, html,..

I'm working on some Reflected Cross-site scripting (XSS) vulnerabilities on our site (php, html,...) AppSpider is reporting one I cannot resolve.

Location: javascript:alert(10829224)

Usually AppSpider lists the url with the js in it. This time it does not. It just lists the querystring: url=javascript:alert(12345)

When I try to test by adding this to the url of the page listed, I get nothing: /path/to/page.html?url=javascript:alert(12345) If I add script tags: /path/to/page.html?url=<script>javascript:alert(12345)</script> I get the alert popup.

Question 1- does javascript:alert() without script tags work? viable js?

Question 2- How can I escape or prevent this type of attack?

We have code to filter out bad unicode chars (thanks: ). It works great on nullifying the <script></script> tags, but apparently it does not help in this case.

Thanks for any tips or tricks

I'm working on some Reflected Cross-site scripting (XSS) vulnerabilities on our site (php, html,...) AppSpider is reporting one I cannot resolve.

Location: javascript:alert(10829224)

Usually AppSpider lists the url with the js in it. This time it does not. It just lists the querystring: url=javascript:alert(12345)

When I try to test by adding this to the url of the page listed, I get nothing: /path/to/page.html?url=javascript:alert(12345) If I add script tags: /path/to/page.html?url=<script>javascript:alert(12345)</script> I get the alert popup.

Question 1- does javascript:alert() without script tags work? viable js?

Question 2- How can I escape or prevent this type of attack?

We have code to filter out bad unicode chars (thanks: http://stackoverflow./questions/3466035/how-to-skip-invalid-characters-in-xml-file-using-php). It works great on nullifying the <script></script> tags, but apparently it does not help in this case.

Thanks for any tips or tricks

Share Improve this question asked May 21, 2019 at 20:16 John CowanJohn Cowan 1,6945 gold badges29 silver badges43 bronze badges 2
  • 1 Use regex to properly filter your URL: Replace(url, @"[^-A-Za-z0-9+&@#/%?=~_|!:,.;()]", ""); and run that on all input you receive. NEVER trust input. – Lulceltech Commented May 21, 2019 at 20:52
  • Possible duplicate of How does XSS work? – miken32 Commented May 21, 2019 at 22:44
Add a ment  | 

3 Answers 3

Reset to default 2

It turns out that the page I'm working on is expecting a relative path to a file in the $_REQUEST['url'] var. So, I was able to take a different approach then trying to parse out or replace javascript. I used php's parse_url() function. Cheap hack, but it works for this one-off page/case.

if (isset($_REQUEST['url']) && valid_script_name_passed_in($_REQUEST['url']) ) {
 ...
}else{
 ...
}

function valid_script_name_passed_in($request_value){
    $parts = parse_url($request_value);
    if( is_array($parts) ){
        if( isset($parts['scheme']) || isset($parts['host'] ){
            return false;
        }
    }
    return true;
}

using "javascript:" in a URL tag will execute the javascript following the colon when the link is clicked.

Can't tell you with certainty without the details, but it seems like the warning is that the "URL=" is vulnerable to user modification, which would allow a user to change the url="javascript:[malicious code goes here]" to inject malicious code.

You used to see this problem a lot on sites where someone could post a URL to their homepage, and without being checked, could just include a javascript instead.

You can't escape it, it needs to be sanitized server-side to prevent a user from being allow to insert javascript code.

Question 1- does javascript:alert() without script tags work?

On your website querystring is sometimes rendered on a page. If it's rendered in html - then tags needed. If it's rendered inside javascript code - then it might work without tags.

Question 2- How can I escape or prevent this type of attack?

General solution is to escape user's input when printing it on a page. In PHP best function for that is htmlspecialchars. It will replace all special characters with html entities. For example,it will replace & to &amp .This way text will look unchanged, but XSS injection will be prevented.

In your case I guess you expect a valid URL in ?url=xxx query parameter. Then escaping will not work, as escaping will destroy URL. In this case you might want to validate if provided string is a valid URL. Here discussed few options for URL validation.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744697562a4588586.html

相关推荐

  • php - XSS with javascript:alert() - Stack Overflow

    I'm working on some Reflected Cross-site scripting (XSS) vulnerabilities on our site (php, html,..

    21小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信