urisanity
Version:
vet URIs in web and web-like applications with confidence
7 lines (6 loc) • 7.76 kB
JavaScript
/*!
* URISanity: Date=Tue Mar 05 2024 02:34:22 GMT+0100 (West Africa Standard Time);NodeBuildVersion=18
*
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).urisanity=t()}(this,(function(){"use strict";var e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t=/^([^\w]*)(unsafe|javascript|vbscript|app|admin|icloud-sharing|icloud-vetting|help|aim|facetime-audio|applefeedback|ibooks|macappstore|udoc|ts|st|jar|x-apple-helpbasic|(?:x\-)?radar)/im,a=/^(?:(?:f|ht)tps?|cid|xmpp|mms|webcal|aaa|acap|bolo|data|blob|file|local|wss?|irc|udp)/im,r=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/?)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\)){0,}(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\!()\[\]{};:\'\"\.\,<>?«»“”‘’]){0,})/i,o=/^(whatsapp|zoommtg|slack|mailto|tel|callto|sms|skype)/im,i=/^(jdbc(:sqlserver|:mysql|:mariadb|:sqlite)?|odbc|postgres(ql)?|mongodb)/im,s=/^(view-source|moz-extension|resource|res|symres|(?:filesystem:|blob:)?chrome-extension|safari|chrome|mxaddon-pkg|mx|mxwebcore|mxjscall|mbinit|safari-resource|opera|webviewprogressproxy|chromenull|chromeinvoke|chromeinvokeimmediate)/im,n=/^((?:jar:)?file|local|blob)/im,c=/^(cloudinary|obsidian|gs|s3|grpc|pptr|tmtbff)/im,d=["widgets.amung.us","v.zilionfast.in","js.blinkadr.com","www.superfish.com","nzj.divdriver.net","istatic.datafastguru.info","widgets.amung.us","xls.searchfun.in","static.image2play.com"],l=/[\u0000-\u001F\u007F-\u009F\u2000-\u200D\uFEFF]/gim,u=/^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp|svg\+xml)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,(?:[a-zA-Z0-9\/+\n=]+)$/i,f=/^data:(?:text\/(?:javascript|html|css|plain))(?:;charset=(UTF-8|iso-8859-7))?,(?:.*)$/im,m=/^(?:vb|java)(?:\s*)?script/im,p=/^(?:(blob:)?https?|wss?|about)/im,v=[".","/"],h="undefined"==typeof self?global||{}:self,b=h.process||{versions:{node:"."},env:{}},w=parseInt(b.versions.node.split(".")[0]);w<=12&&(h.URL||(h.URL=function(e){var t=require("url"),a=w<=11?t.parse(e):t.URL(e);return Object.assign({},a,{hostname:a.host})}));var g,y=void 0!==(g=h.navigator)&&null===g.product.match(/^(ReactNative|NativeScript|NS)$/i)?h.location.origin:(h.constants||b.env).ORIGIN;function F(e){return"string"==typeof e&&v.indexOf(e.charAt(0))>-1}function A(e){var t=void 0,a=void 0,r=void 0,o=void 0,i=void 0;o={};var s=e instanceof h.FormData?e.entries():new h.FormData(e).entries();try{for(;null!==(a=s.next().value);)r=a[0],i=a[1],Object.prototype.hasOwnProperty.call(o,r)?(t=o[r],Array.isArray(t)||(t=o[r]=[t]),t.push(i)):o[r]=i}catch(e){o=Object.fromEntries(s)}return JSON.stringify(o)}function L(e){var f=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e||null!==e.match(/:\/\/(?:[#$@=*.!]|[/]){0,}$/)||e.includes("////////////"))return"about:blank";var v=e.replace(l,"").trim();if(F(v)){var b=v.startsWith("/")?y+v:y+"/"+v;v=r.test(b)?b:"//"}var w=v.match(a)||v.match(o)||v.match(i)||v.match(s)||v.match(c)||v.match(p),g=(w=null!==w?w:[])[0]||"";try{var A=new h.URL(v.toLowerCase()),L=A.hostname,j=A.pathname,x=A.search,C=A.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d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/.test(L)||/^(?:((?:[a-z0-9-._~]{0,}|%[1-9a-f]?[0-9a-f]|[!$&'()*+,;=])|\:|\@)*)/i.test(j)||/^((?:[a-z0-9-._~]{0,}|%[1-9a-f]?[0-9a-f]|[!$&'()*+,;=])|\:|\@|\/|\?)*$/i.test(x)||/^((?:[a-z0-9-._~]{0,}|%[1-9a-f]?[0-9a-f]|[!$&'()*+,;=])|\:|\@|\/|\?)*$/i.test(C)){if(L.includes(".00")||-1!==d.indexOf(L))return"about:blank";if(j.toLowerCase().includes("'")||j.toLowerCase().includes("%29")||j.toLowerCase().includes("%28")||j.toLowerCase().includes("%20")||j.toLowerCase().includes("%22")||j.toLowerCase().includes(""")||j.toLowerCase().includes("(")||j.toLowerCase().includes(")")||j.toLowerCase().includes("%3e")||j.toLowerCase().includes("%3c")||j.toLowerCase().includes("><"))return"about:blank";if(null!==x.toLowerCase().match(/%3c(?=\/)?/g)||x.toLowerCase().includes("%3e")||x.toLowerCase().includes("%3f")||x.toLowerCase().includes("%3d")||x.toLowerCase().includes("%27")||x.toLowerCase().includes("%22")||x.toLowerCase().includes("'")||x.toLowerCase().includes(""")||null!==x.toLowerCase().match(/\.(?:jar|dmg|exe|bin|sh|sed|py)/g))return"about:blank"}}catch(e){if(e)return"about:blank"}if(!t.test(g)||r.test(v)){var O=!1;return f.allowScriptOrDataURI&&null!==g.match(/^(java|vb)script|data/)&&(u.test(v)||m.test(v))&&(O=!0),f.allowCommsAppURI&&o.test(v)&&(O=!0),f.allowDBConnectionStringURI&&i.test(v)&&(O=!0),f.allowServiceAPIURI&&c.test(v)&&(O=!0),f.allowBrowserSpecificURI&&s.test(v)&&(O=!0),f.allowWebTransportURI&&p.test(v)&&(O=!0),f.allowFileSystemURI&&n.test(v)&&(O=!0),""!==g&&O?v:"about:blank"}}var j={isSameOrigin:function(e){if(!e||f.test(e.trim())||u.test(e.trim()))return!1;try{var t=new h.URL(e.trim());return y===t.origin}catch(e){if(e)return!1}},extractParamValueFromUri:function(e,t){if(!e||f.test(e.trim())||u.test(e.trim()))return null;var a=new RegExp("[\\?&#]"+t+"=([^&#]*)").exec(e.trim());return null!=a?unescape(a[1]):void 0},checkParamsOverWhiteList:function(t){var a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";if(!t||f.test(t.trim())||u.test(t.trim()))return!1;if("object"!==(void 0===a?"undefined":e(a)))return!1;var o=new h.URL(t.trim()),i=[],s=[],n=null;try{var c="";if("FormData"in h&&r instanceof h.FormData)if("function"==typeof Object.fromEntries)c=A(r);else{var d={};r.forEach((function(e,t){d[t]=e})),c=JSON.stringify(d)}else c=r;"string"==typeof c&&(n=JSON.parse(c))}catch(e){n=r}if(""===n?o.searchParams.forEach((function(){for(var e=arguments.length,t=Array(e),a=0;a<e;a++)t[a]=arguments[a];var r=t[0],o=t[1];s.push(unescape(r)),i.push(o)})):n instanceof Object&&s.concat(Object.values(n)),i.length===s.length)if(a instanceof Array){if(i.length===a.length&&i.slice(0).sort().join("|")===a.slice(0).sort().join("|"))return!0}else if(a instanceof Object){for(var l=0;l<i.length;l++){var m=i[l],p=s[l],v=a[m];if(!(v instanceof RegExp))throw new Error('"'+m+'" does not have a matching regex pattern to match "'+p+'"');if(!v.test(p))break}if(l===s.length)return!0}return!1},vet:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return L(e,t||{})}};return j}));
//# sourceMappingURL=urisanity.min.js.map