Skip to content

Instantly share code, notes, and snippets.

@tokkonopapa
Last active April 24, 2018 14:29
Show Gist options
  • Save tokkonopapa/680f6b5d2902000faa8ebcaa18bf28aa to your computer and use it in GitHub Desktop.
Save tokkonopapa/680f6b5d2902000faa8ebcaa18bf28aa to your computer and use it in GitHub Desktop.
Possible fixed version as 3.0.10.5
/*
Project: WP-ZEP - Zero-day exploit Prevention for wp-admin
Copyright (c) 2013-2018 tokkonopapa ([email protected])
This software is released under the MIT License.
*/
!function(e,t,n){"use strict";function r(e){return e=e.replace(y.home+y.admin,""),C.hasOwnProperty(e)?C[e]:null}function o(e){var t=n.createElement("div");return t.appendChild(n.createTextNode(e)),e=t.innerHTML.replace(/["']/g,function(e){return{'"':"&quot;","'":"&#39;"}[e]}),t="",e}function a(e){e=e?e.toString():"";var t=e.match(/^(?:([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/);return{scheme:t[1]||"",relative:t[2]||"",authority:t[3]||"",path:t[4]||"",query:t[5]||"",fragment:t[6]||""}}function i(e){return(e.scheme?e.scheme+":":"")+(e.relative+e.path)+(e.query?"?"+e.query:"")+(e.fragment?"#"+e.fragment:"")}function c(e,n){"object"!=typeof e&&(e=a(e||t.location.href));for(var r=e.query?e.query.split("&"):[],o=r.length;o-- >0;)if(0===r[o].indexOf(w.name)){r.splice(o,1);break}return r.push(w.name+"="+encodeURIComponent(n)),e.query=r.join("&"),i(e)}function h(e){return(!e.scheme||/^https?$/.test(e.scheme))&&(e.path||e.query)}function s(e){try{e=e||t.location.pathname||""}catch(n){e=""}var r=a(e.toLowerCase());if(h(r)){if(r=k(e),r.origin!==t.location.origin)return-1;if(e=b.exec(r.pathname),e&&(0<=e[0].indexOf(y.admin+"admin-")||0<=e[0].indexOf(y.admin)||0<=e[0].indexOf(y.plugins)||0<=e[0].indexOf(y.themes)))return 1}return 0}function f(){return 1===s(t.location.pathname)||t.location.search.indexOf(w.name)>=0}function p(e){var t,n,r=y.sites.length;for(t=0;r>t;++t)if(n=e.indexOf(y.sites[t]+"/"),n>=0&&6>=n)return!0;return!1}function l(e){return/\/$/.test(e.path)}function u(e){return-1!==(e.attr("rel")||"").indexOf("nofollow")}function m(t,n,r){var o=e._data(t[0]).events,a=o[n],i=r?a.splice(a.delegateCount-1,1)[0]:a.pop();a.splice(r?0:a.delegateCount||0,0,i)}function d(t,n,r){var o=n.split(/\s+/);t.each(function(t){for(t=0;t<o.length;++t){var n=e.trim(o[t]).match(/[^\.]+/i)[0];m(e(this),n,r)}})}function g(){var r=e(n);r.onFirst("click contextmenu","a",function(n){var r=0,i=e(this),m=i.attr("href")||"",d=a(m);if(h(d)&&(r=s(m)),"click"===n.type)if(1===r)i.attr("href",l(d)?m:c(m,u(i)?"nofollow":y.nonce));else if(-1===r&&f())if("_self"===i.attr("target")||p(m))i.attr("href",l(d)?m:c(m,u(i)?"nofollow":y.nonce));else if(!this.hasAttribute("onClick"))return m=m.split(";",2).shift(),m=o(decodeURIComponent(this.href)),r=t.open(),r.document.write('<!DOCTYPE html><html><head><meta name="referrer" content="never" /><meta name="referrer" content="no-referrer" /><meta http-equiv="refresh" content="0; url='+m+'" />'+(e("body").hasClass("webview")?'<script>window.location.replace("'+m+'")</script>':"")+"</head></html>"),r.document.close(),n.stopImmediatePropagation(),!1}),r.onFirst("submit","form",function(){var t=e(this),n=t.attr("action");1===s(n)&&("post"===(t.attr("method")||"").toLowerCase()?t.attr("action",c(n,y.nonce)):t.append('<input type="hidden" name="'+w.name+'" value="'+y.nonce+'">'))})}function v(){if(!w.init){if(w.init=!0,e("img").each(function(){var t=e(this).attr("src");1===s(t)&&e(this).attr("src",c(t,y.nonce))}),"undefined"!=typeof t._wpRevisionsSettings){var n,r=t._wpRevisionsSettings.revisionData,o=r.length;for(n=0;o>n;++n)-1===r[n].restoreUrl.indexOf(w.name)&&(t._wpRevisionsSettings.revisionData[n].restoreUrl=c(r[n].restoreUrl,y.nonce))}e("#toplevel_page_ip-geo-block li.wp-first-item").each(function(){var t=e(this);t.css("display","IP Geo Block"===t.children("a").text()?"none":"block")})}}var y=IP_GEO_BLOCK_AUTH,w={init:!1,name:"ip-geo-block-auth-nonce"},b=new RegExp("^(?:"+(y.home||"")+y.admin+"|"+(y.home||"")+y.plugins+"|"+(y.home||"")+y.themes+")(?:.*.php|.*/)?$"),x=function(e){for(var t=e.length;t-- >0;)if(-1!==e[t].indexOf("request%5Bbrowse%5D=ip-geo-block-auth")){e[t]="request%5Bbrowse%5D=featured";break}return e},O=function(e){for(var t=e.length;t-- >0;)if(-1!==e[t].indexOf("query%5Bip-geo-block-auth-nonce%5D=")){delete e[t];break}return e},C={"upload.php":O,"theme-install.php":x,"network/theme-install.php":x},k=function(){var e=null;try{new URL("/","http://example.com/")}catch(r){try{e=(new DOMParser).parseFromString("<html><head></head><body></body></html>","text/html")}catch(o){e=n.implementation.createHTMLDocument("")}}return function(r,o){var a,i,c,h=n;if(r="undefined"!=typeof r?r:t.location.href,null===e){"undefined"==typeof o&&(o=t.location.href);try{c=new URL(r,o)}catch(s){c=new URL(r,t.location.href)}}else{if("undefined"!=typeof o){for(h=e;h.head.firstChild;)h.head.removeChild(h.head.firstChild);a=h.createElement("base"),a.setAttribute("href",o),h.head.appendChild(a)}i=h.createElement("a"),i.setAttribute("href",r),i.setAttribute("href",i.href),c={protocol:i.protocol,host:i.host,hostname:i.hostname,port:i.port,pathname:i.pathname,search:i.search,hash:i.hash,href:i.href,username:"",password:"",origin:i.origin||null},"http:"===c.protocol&&"80"===c.port?(c.port="",c.host=c.host.replace(/:80$/,"")):"https:"===c.protocol&&"443"===c.port&&(c.port="",c.host=c.host.replace(/:443$/,"")),"http:"!==c.protocol&&"https:"!==c.protocol||(c.pathname&&"/"!==c.pathname.charAt(0)&&(c.pathname="/"+c.pathname),c.origin||(c.origin=c.protocol+"//"+c.hostname+(c.port?":"+c.port:"")))}if(c.username||c.password)throw new URIError(c.username+":"+c.password);return c}}();e.ajaxPrefilter(function(e){if(1===s(e.url)&&!e.url.match(/async-upload\.php$/))if("undefined"!=typeof t.FormData&&e.data instanceof FormData)e.data.append(w.name,y.nonce);else{var n,o,i=a(e.url);"undefined"==typeof e.data||i.query?e.url=c(i,y.nonce):(n=e.data?e.data.split("&"):[],o=r(t.location.pathname),o&&(n=o(n)),n.push(w.name+"="+encodeURIComponent(y.nonce)),e.data=n.join("&"))}}),"undefined"==typeof e.fn.onFirst&&(e.fn.onFirst=function(t,n){var r,o=e(this),a="string"==typeof n;if(e.fn.on.apply(o,arguments),"object"==typeof t)for(r in t)t.hasOwnProperty(r)&&d(o,r,a);else"string"==typeof t&&d(o,t,a);return o}),e(t).on("error",function(){v()}),e(function(){v()}),g()}(jQuery,window,document);
@tokkonopapa
Copy link
Author

Potential fixed version against the issue of #38 and Conflict with Wordfence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment