Skip to content

Instantly share code, notes, and snippets.

@gareth-gillman
Created August 30, 2016 10:19
Show Gist options
  • Save gareth-gillman/2faefab6b06c4f39385eece74f41d8cb to your computer and use it in GitHub Desktop.
Save gareth-gillman/2faefab6b06c4f39385eece74f41d8cb to your computer and use it in GitHub Desktop.
Checks links on a website for the _blank attribute and adds the noopener and noreferrer tags if they don't exist - see https://dev.to/ben/the-targetblank-vulnerability-by-example
$(document).ready(function(){
$('a').each(function() {
if(
$(this).attr('target') == '_blank' ||
$(this).attr('rel') == 'noopener' ||
$(this).attr('rel') == 'noreferrer' ) {
$(this).attr('rel', 'noopener noreferrer');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment