PAC - JavaScript - shExpMatch() vs dnsDomainIs()
Asked Answered
F

2

9

What is the difference between shExpMatch() and dnsDomainIs()

The definition says:

// dnsDomainIs()
// Evaluates hostnames and returns true if hostnames match. Used mainly to match and exception individual host names.

// Example:
if (dnsDomainIs(host, ".google.com")) return "DIRECT";



// shExpMatch()
// Attempts to match hostname or URL to a specified shell expression and returns true if matched.

// Example:
if (shExpMatch(url, "*vpn.domain.com*") ||
      shExpMatch(url, "*abcdomain.com/folder/*"))
  return "DIRECT";

If I understand it correct then

shExpMatch() - can use some wildcards

dnsDomainIs() - can use exact names

Is shExpMatch() just superior to dnsDomainIs()

Fleet answered 16/2, 2015 at 0:56 Comment(0)
C
5

Looking at the definitions from http://findproxyforurl.com/pac-functions/ , they have very different functionality. dnsDomainIs() uses exact domain names - such as .google.com, while shExpMatch() uses shell-like strings with wildcards such as *.google.com.

They look very different now, but with shExpMatch, you can also match items in a folder structure like example.com/sub/folder/* or http://example.com/img/*.png.

The first one only matches the hostname without protocol, port or subfolders, while the second one matches the whole URL. However, you may be able to use shExpMatch() like dnsDomainIs(), but I am not sure, if you may be vulnerable then by inadvertedly allowing a URL like google.com.example.com for google.com - dnsDomainIs() would return false here, shExpMatch() may return true (not tested, just a hunch)

Choroid answered 6/3, 2015 at 13:35 Comment(0)
W
0

beware the following in firefox 52.0...

dnsDomainIs("www.notmycompany.com", "mycompany.com") returns true dnsDomainIs("www.myCompany.com", "mycompany.com") returns false

Whimper answered 10/3, 2017 at 2:32 Comment(1)
One may put the . so that dnsDomainIs("www.notmycompany.com", ".mycompany.com") returns false.Hexad

© 2022 - 2024 — McMap. All rights reserved.