Today's XSS onmouseover exploit on twitter.com

后端 未结 5 656
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 09:32

Can you explain what exactly happened on Twitter today? Basically the exploit was causing people to post a tweet containing this link:

http://t.co/@\"style=\"fon         


        
5条回答
  •  难免孤独
    2020-12-23 09:55

    The vulnerability is because URLs were not being parsed properly. For example, the following URL is posted to Twitter:

    http://thisisatest.com/@"onmouseover="alert('test xss')"/
    

    Twitter treats this as the URL. When it is parsed Twitter wraps a link around that code, so the HTML now looks like:

    http://thisisatest.com/@"onmouseover="alert('test xss')"/ 
    

    You can see that by putting in the URL and the trailing slash, Twitter thinks it has a valid URL even though it contains a quote mark in it which allows it to escape (ie. terminate the href attribute, for the pedants out there) the URL attribute and include a mouse over. You can write anything to the page, including closing the link and including a script element. Also, you are not limited by the 140 character limit because you can use $.getScript().

    This commit, if it were pulled, would have prevented this XSS vulnerability.

    In detail, the offending regex was:

    REGEXEN[:valid_url_path_chars] = /(?:
      #{REGEXEN[:wikipedia_disambiguation]}|
      @[^\/]+\/|
      [\.\,]?#{REGEXEN[:valid_general_url_path_chars]}
    )/ix
    

    The @[^\/]+\/ part allowed any character (except a forward slash) when it was prefixed by an @ sign and suffixed by a forward slash.

    By changing to @#{REGEXEN[:valid_general_url_path_chars]}+\/ it now only allows valid URL characters.

提交回复
热议问题