Skip to content

Commit

Permalink
Fix open redirect if Adminer is accessible at //adminer.php%2F@ (than…
Browse files Browse the repository at this point in the history
…ks to Prakash Sharma)
  • Loading branch information
vrana committed May 11, 2020
1 parent a9c1004 commit 6a2de87
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion adminer/include/bootstrap.inc.php
Expand Up @@ -84,7 +84,7 @@

define("SERVER", $_GET[DRIVER]); // read from pgsql=localhost
define("DB", $_GET["db"]); // for the sake of speed and size
define("ME", str_replace(":", "%3a", preg_replace('~^[^?]*/([^?]*).*~', '\1', $_SERVER["REQUEST_URI"])) . '?'
define("ME", str_replace(":", "%3a", preg_replace('~\?.*~', '', relative_uri())) . '?'
. (sid() ? SID . '&' : '')
. (SERVER !== null ? DRIVER . "=" . urlencode(SERVER) . '&' : '')
. (isset($_GET["username"]) ? "username=" . urlencode($_GET["username"]) . '&' : '')
Expand Down
9 changes: 8 additions & 1 deletion adminer/include/functions.inc.php
Expand Up @@ -721,12 +721,19 @@ function format_time($start) {
return lang('%.3f s', max(0, microtime(true) - $start));
}

/** Get relative REQUEST_URI
* @return string
*/
function relative_uri() {
return preg_replace('~^[^?]*/([^?]*)~', '\1', $_SERVER["REQUEST_URI"]);
}

/** Remove parameter from query string
* @param string
* @return string
*/
function remove_from_uri($param = "") {
return substr(preg_replace("~(?<=[?&])($param" . (SID ? "" : "|" . session_name()) . ")=[^&]*&~", '', "$_SERVER[REQUEST_URI]&"), 0, -1);
return substr(preg_replace("~(?<=[?&])($param" . (SID ? "" : "|" . session_name()) . ")=[^&]*&~", '', relative_uri() . "&"), 0, -1);
}

/** Generate page number for pagination
Expand Down
1 change: 1 addition & 0 deletions changes.txt
@@ -1,4 +1,5 @@
Adminer 4.7.7-dev:
Fix open redirect if Adminer is accessible at //adminer.php%2F@

Adminer 4.7.6 (released 2020-01-31):
Speed up alter table form (regression from 4.4.0)
Expand Down

0 comments on commit 6a2de87

Please sign in to comment.