TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Hacking the <a> tag in 100 characters

53 pointsby bilawalabout 12 years ago

41 comments

Cushmanabout 12 years ago
I thought this was sensationalist the last time it came up, and I still do.<p>This is an attack which targets people who are carefully checking the link URL before clicking, but who then ignore the actual content of their URL bar. That has to be a pretty limited group, right? And this is far from the only way to spoof a link in JavaScript, so to really make this impossible would mean disabling swaths of functionality used widely across the web, i.e. not gonna happen.[0]<p>And it's counterproductive. Since the birth of the web we've been trying to drill into people's skulls not to trust <i>anything</i> except what it says in your URL bar after "https:". We need to avoid anything that would give users any other impression.<p>That said, there is a useful message here, not "this is a problem with JavaScript" but "this is another reason you must personally validate the domain name before entering any personal information."<p>[0] On a large scale, that is. Obviously some people here are comfortable with disabling swaths of JavaScript across the web.
评论 #5390101 未加载
评论 #5390058 未加载
评论 #5390019 未加载
评论 #5390049 未加载
评论 #5390054 未加载
lukiferabout 12 years ago
While this should probably be fixed as prescribed by the author, it's relatively easy for a no-goodnik to accomplish the same goal without touch the href:<p><pre><code> $("a").click(function(e){ e.preventDefault(); document.location="http://evilsite.paypa1.com"; }); </code></pre> In either case, a right-click to open or copy/paste sidesteps, though that's just a kludge.
评论 #5391131 未加载
评论 #5431678 未加载
batisteabout 12 years ago
This is not a hack it's basic Javascript.<p>If a malicious hacker can insert some script in a trusted page, security is pretty much completly broken and you have other worries. The fact that you can make links in this page point to other malicious pages seems like a small problems as most people won't even check the domain before clicking the link.<p>I would think that some users are most likely to check the address bar after clicking the link. But my dad would probably woudn't see anything.
评论 #5390070 未加载
karolisdabout 12 years ago
I eagerly awaiting your blog post when you discover preventDefault()
评论 #5390080 未加载
评论 #5389962 未加载
评论 #5390081 未加载
homakovabout 12 years ago
you kidding right? while we have real world problems (URL detections, cookies etc check homakov.blogspot.com) you ask w3c to do what? To deny redirecting to other websites and changing href after click? I can tell you more horror JS tricks, but they are not fixed yet.
johnjansenabout 12 years ago
I work on the IE team at Microsoft, and I really don't think this is an exploit. If you can control the script for the click event, then you already have control of the page and can do worse (think: cross-site scripting). In this case, if you browse to my site and I'm a bad guy and want to send you to evil.com, I'd just craft a page that makes you think the whole page is honorable, rather than hope you click on a link. In other words, anyone who can hack the click event already owns you.<p>I'm very happy to reassess if you have an example where you do not control the content of the page, but somehow still control the content of the click. That would be really serious and worth fixing.<p>-John Jansen Principal Test Lead Internet Explorer
mojubaabout 12 years ago
I use this trick to mask email addresses in mailto: links, i.e. something like:<p><pre><code> &#60;a onClick="this.href= ['mailto',[['john','doe'].join('.'), ['gmail','com'].join('.')].join('@')].join(':')" href=#click-to-email&#62; </code></pre> I don't know how good my solution is in protecting from spammers' scrapers but I'd be happy to hear about any alternatives.
评论 #5411151 未加载
jvaticabout 12 years ago
In addition to countless other oversights, setTimeout would not work as you suggested in the post as the page would be unloaded before it ever executed. And, as others have already mentioned, there are numerous other ways to accomplish the exact same effect with 'more legitimate' methods (e.g. event.preventDefault(); window.location = ...).<p>Various browsers such as Chrome will warn/block you from visiting known malicious sites, but it comes down to being aware of where you are before entering personal information.<p>I think a better proposal might be getting browsers to warn users if the url they are visiting is sufficiently different from the original href attribute (i.e. different host). Something like this could easily be done with a browser extension (and could handle more cases such as preventDefault + window.location = ...).
enigmangoabout 12 years ago
Firefox 21 (Aurora), I got sent to PayPal - just realized that I had NoScript on, though. Allowed scripts for bilaw.al, tried again, and I got sent to the dummy page.<p>I got sent to the dummy page on Opera 12.13 and Chrome 25. Just updated to Opera 12.14 and I still got sent to the dummy page. Running Windows 7.
burgerguygabout 12 years ago
You can set up a span with a style that has a link-like look (color, underline), use "cursor:pointer" in the style to make the pointer turn to a hand over it. Use a mouseover/out event catcher to trigger a tooltip that mimics the mouseover behavior on links, then capture the click event on the span to send the user to another page.<p>You can use JavaScript to swap out all the links for spans like these.<p>If you're on a site that's using intentionally deceptive JavaScript or getting malicious JavaScript injected, whether or not links go where you think they will is the least of your problems.
DPLeoabout 12 years ago
I just tried clicking your "Paypal" link in Chrome 25, Firefox 19, and IE9. All of them allowed the href to change and went to what could have been the phishing site. Then I went back and tried right-clicking the "Paypal" link and open in a new tab. All 3 browsers went to Paypal.<p>I like your suggestion to have behavior changed so the browsers don't allow the href to be changed to another domain without warning the user. Until that happens, maybe opening links in a new tab (or window) is a good practice.<p>Enjoy!
Xeno22about 12 years ago
The reason for onclick is exactly the mentioned "problem". I use &#60;a&#62; tags to show them as links, but without reference, only with onclick events to load the actual request. So if any browser manufacturer tries to kill this behaviour (like x-site scripting bullshit) the world will go oom...<p>So, if you do not like the javascript events -&#62; disable javascript interpreter in your browser!<p>It would make more sense to kill IE, ActiveX, Flash and Java-Plugins...
dougaitkenabout 12 years ago
right click open in new tab takes you to the original link. So this must be done in session or something and the alt-open in next tab take the plain link URL?
评论 #5389928 未加载
cthackersabout 12 years ago
So did you just discovered DOM manipulation with JavaScript ? What would a browser fix be like in your opinion ? Disallow JavaScript to add event listeners and/or modify Node properties ?<p>Google Analytics hooks on links to track clicks and exit pages and so on. Would you really enjoy an alert every time you click on something ? I am amazed how you people come up with crap like this.<p>Enjoy your 5 minutes of traffic while they last
Tichyabout 12 years ago
I dislike loggin in to sites that I have been referred to by other sites in general. Not sure if there is a solution for paypal? Like getting an transaction id from a shop, then logging on to PayPal and paying that transaction id?<p>Might be something worthwhile to provide a solution for (possibly even a valid use case for QR codes - pay with phone on a web site)? But then, not many people will care, I suspect :-/
bjazmooreabout 12 years ago
I noticed that at least one other person suggested opening the link in a new tab. This seems to defeat this hack in Chrome and IE 9. It probably defeates it in all browsers, since the new tab is in a different context than where the javascript is being executed and therefore can not be redirected by the javascript.
评论 #5407725 未加载
Tarlachabout 12 years ago
Fun fact: On Chrome, Opening the link in a new tab does not redirect to the phishing site. However, normal clicking does. Context changing seems to make this work, as chrome delegates the href to a new process, and does not execute the JS embed.
imackabout 12 years ago
Chrome 25, I got sent to Paypal.
评论 #5389832 未加载
评论 #5390680 未加载
评论 #5389873 未加载
评论 #5389882 未加载
arjeezyboomabout 12 years ago
This may be the dumbest blog post I've ever read. The fact that this is possible (and necessary) speaks more to the general glacial nature of the HTML standards and JS to provide the functionality we expect of our web apps.
adamzr86about 12 years ago
Right clicking the link and choosing "Open in new tab" with Chrome does not execute the JavaScript. This is good and bad. Good because it solves your problem, bad because it makes the link unpredictable.
skramabout 12 years ago
So many sites use this for various reasons like appending tracking codes (my former employer did this for Omniture tracking).. I just don't see this suggestion to disable the functionality catching on.
评论 #5389761 未加载
unimpressiveabout 12 years ago
Before I turned off noscript, I was very confused about how bilawal came into possession of paypal.com.<p>It took me a few seconds before I realized how stupid that entire line of thought was.
xyzzybabout 12 years ago
"If someone has control of the DOM the game is already over"<p><a href="http://www.frameloss.org/2012/10/28/hover-fail/" rel="nofollow">http://www.frameloss.org/2012/10/28/hover-fail/</a>
Rodormabout 12 years ago
Firefox 19.0.2 on Linux shows the JS Pishing link on mouseover, Firefox 19.0.2 on Windows 7 doesn't! So, Firefox 19.0.2 on Linux is the only safe browser.
gaaahabout 12 years ago
Offline web apps saved to the home screen in iOS must do this for internal links: otherwise you end up opening safari for every link you click on
thebezetabout 12 years ago
Don't want to sound rude, but I've known about this for literally years.<p>I think anyone who makes single page web apps uses this "hack" on an everyday basis.
bilawalabout 12 years ago
I've updated the pledge - I'm now asking major browsers to warn users if a link is changed to another domain from what it originally was.
Kwpolskaabout 12 years ago
&#62; Let me show you an example. This link should take you to PayPal.<p>The href is leading to bitly, making much less people believe you.
GraphWhit3about 12 years ago
Firefox Nightly loads Paypal page fine without any issue. So I think it is already fixed in upcoming Firefox versions.
评论 #5414279 未加载
sgoelabout 12 years ago
<p><pre><code> var links = document.links </code></pre> is a more efficient way to get an array of all of the links on a page.
switzabout 12 years ago
I believe your code is incorrect:<p><pre><code> for(var i=0; i &#60; links.length; j++){ // j++ =&#62; i++</code></pre>
评论 #5389867 未加载
curiousmonkeyabout 12 years ago
Question - can the script be modified to act upon a middle click or 'Open in new tab' function?
rihananewabout 12 years ago
hmmm nice though and this is the mainly reason of Phishing page because when we make a Phishing page then we have to use this step to change the URL when victim click on that.... that's why phishing is happening ...<p>so read this news carefully and be aware for futue...
claudiusabout 12 years ago
It doesn’t appear to work in Opera version 12.14, I get sent to PayPal :)
评论 #5389822 未加载
andrew_isidoroabout 12 years ago
Interesting that it doesn't effect "Open in new tab" links in Chrome...
评论 #5420185 未加载
accurrentabout 12 years ago
If you click open in new tab in chrome it does not work :)
Cloopabout 12 years ago
right-click open in new tab and windows in firefox open the paypal link opposed to fishing page- funny enough the paypal link is a redirect via paypal
evilpieabout 12 years ago
Why ECMA? Sounds more like something for w3c or whatwg.
评论 #5389885 未加载
apaantuhabout 12 years ago
google will disagree with your proposal...
评论 #5389727 未加载
rassarabout 12 years ago
please, even shorter! for(i in o=document.links){o[i].onclick=function(){this.href='//j.mp/141nisR'}}
orbital303about 12 years ago
This is incorrect. Once you get to see the url in the bar, it's too late if you've been redirected to a site with malware. This is an extremely serious security flaw and downplaying it is not going to help anyone.<p>There is no use for this security hole other than to deceive people. Period.
评论 #5420225 未加载
评论 #5390035 未加载
评论 #5390064 未加载