Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML attributes that can contain javascript

I'm looking for a simple list of all the html attributes that can contain javascript that will automatically run when an action is performed. I know this will differ between browsers and versions but I'd rather be safer than sorry. I currently know of the following javascript attributes: onload, onclick, onchange, onmouseover, onmouseout, onmousedown, and onmouseup

Backstory: I'm getting a full html document from an untrusted source and I want to strip all javascript that could run from the original html document so I'm removing all script tags as well as any attributes that could hold javascript before its displayed in an iframe. For this implantation there is no server side processing and no way of sandboxing the code since I need to run javascript that is being added locally after all of the original javascript is removed.

like image 423
Scott Avatar asked Jan 09 '15 01:01

Scott


People also ask

What are the attributes of JavaScript?

Property Attributes Other attributes are: enumerable, configurable, and writable. These attributes define how the property can be accessed (is it readable?, is it writable?) In JavaScript, all attributes can be read, but only the value attribute can be changed (and only if the property is writable).

What are the 3 types of attribute in HTML?

HTML attributes are generally classified as required attributes, optional attributes, standard attributes, and event attributes: Usually the required and optional attributes modify specific HTML elements. While the standard attributes can be applied to most HTML elements.


1 Answers

There are two places where Javascript can be used in HTML attributes:

  1. Any onEVENT attribute. I suggest just treating any attribute that begins with on as an event binding, and strip them all out.

  2. Any attribute that can contain a URI will be executed as Javascript if the URI uses the javascript: scheme, such as href and src. A complete list is in

COMPLETE list of HTML tag attributes which have a URL value?

like image 51
Barmar Avatar answered Oct 03 '22 23:10

Barmar