client9 / client9/libinjection
False positives with JavaScript on.*
- Dominant language
- C
- Stars
- 1k
- Forks
- 282
- PR merge metrics
- No merged PRs in 30d
Description
The matches for JavaScript on.* generate a few false positives, e.g. with cookies that contain base64-encoded md5sums, e.g. `Cookie: foo=...ZQ/ONSQg==`. The vast majority of those false positives could be prevented if the string was tested explicitly against the known event handlers. The following patch should achieve this, but I've only verified that it compiles:
```
--- apache2/libinjection/libinjection_xss.c 2020-09-17 18:36:22.931339872 +0200
+++ apache2/libinjection/libinjection_xss.c 2020-09-17 18:37:17.363861440 +0200
@@ -210,6 +210,71 @@
, NULL
};
+/* Blacklist of known JS GlobalEventHandlers */
+static const char* BLACKGEHS[] = {
+ "onabort"
+ , "onanimationcancel"
+ , "onanimationend"
+ , "onanimationiteration"
+ , "onauxclick"
+ , "onblur"
+ , "oncancel"
+ , "oncanplay"
+ , "oncanplaythrough"
+ , "onchange"
+ , "onclick"
+ , "onclose"
+ , "oncontextmenu"
+ , "oncuechange"
+ , "ondblclick"
+ , "ondurationchange"
+ , "onended"
+ , "onerror"
+ , "onfocus"
+ , "onformdata"
+ , "ongotpointercapture"
+ , "oninput"
+ , "oninvalid"
+ , "onkeydown"
+ , "onkeypress"
+ , "onkeyup"
+ , "onload"
+ , "onloadeddata"
+ , "onloadedmetadata"
+ , "onloadend"
+ , "onloadstart"
+ , "onlostpointercapture"
+ , "onmousedown"
+ , "onmouseenter"
+ , "onmouseleave"
+ , "onmousemove"
+ , "onmouseout"
+ , "onmouseover"
+ , "onmouseup"
+ , "onpause"
+ , "onplay"
+ , "onplaying"
+ , "onpointercancel"
+ , "onpointerdown"
+ , "onpointerenter"
+ , "onpointerleave"
+ , "onpointermove"
+ , "onpointerout"
+ , "onpointerover"
+ , "onpointerup"
+ , "onreset"
+ , "onresize"
+ , "onscroll"
+ , "onselect"
+ , "onselectionchange"
+ , "onselectstart"
+ , "onsubmit"
+ , "ontouchcancel"
+ , "ontouchstart"
+ , "ontransitioncancel"
+ , "ontransitionend"
+ , "onwheel"
+};
static int cstrcasecmp_with_null(const char *a, const char *b, size_t n)
{
@@ -332,6 +397,26 @@
return 0;
}
+static int is_black_geh(const char* s, size_t len)
+{
+ const char** eh;
+
+ if (len < 3) {
+ return 0;
+ }
+
+ black = BLACKGEHS;
+ while (*eh != NULL) {
+ if (cstrcasecmp_with_null(*eh, s, len) == 0) {
+ /* printf("Got black event handler %s\n", *eh); */
+ return 1;
+ }
+ eh+= 1;
+ }
+ return 0;
+}
+
+
static attribute_t is_black_attr(const char* s, size_t len)
{
stringtype_t* black;
@@ -344,10 +429,11 @@
/* JavaScript on.* */
if ((s[0] == 'o' || s[0] == 'O') && (s[1] == 'n' || s[1] == 'N')) {
/* printf("Got JavaScript on- attribute name\n"); */
- return TYPE_BLACK;
- }
-
+ if (is_black_geh(s, len)) {
+ return TYPE_BLACK;
+ }
+ }
/* XMLNS can be used to create arbitrary tags */
if (cstrcasecmp_with_null("XMLNS", s, 5) == 0 || cstrcasecmp_with_null("XLINK", s, 5) == 0) {
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.