Skip to content

Commit 21d3a31

Browse files
committed
Avoid denial-of-service via version check (GHSA-q4f2-39gr-45jh, regression from 4.6.2)
1 parent e4ac9d6 commit 21d3a31

File tree

5 files changed

+12
-52
lines changed

5 files changed

+12
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Adminer dev
2+
- Avoid denial-of-service via version check (GHSA-q4f2-39gr-45jh, regression from 4.6.2)
23
- Pretty print JSON in edit
34
- Support multiline generated values in alter table
45
- Link //domain.tld values

adminer/include/bootstrap.inc.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@
2929
include "../adminer/file.inc.php";
3030
}
3131

32-
if ($_GET["script"] == "version") {
33-
$filename = get_temp_dir() . "/adminer.version";
34-
@unlink($filename); // it may not be writable by us, @ - it may not exist
35-
$fp = file_open_lock($filename);
36-
if ($fp) {
37-
file_write_unlock($fp, serialize(array("signature" => $_POST["signature"], "version" => $_POST["version"])));
38-
}
39-
exit;
40-
}
41-
4232
// Adminer doesn't use any global variables; they used to be declared here
4333

4434
if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility

adminer/include/design.inc.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,8 @@ function page_header(string $title, string $error = "", $breadcrumb = array(), s
6262
adminer()->bodyClass();
6363
echo "'>\n";
6464
$filename = get_temp_dir() . "/adminer.version";
65-
if (!$_COOKIE["adminer_version"] && function_exists('openssl_verify') && file_exists($filename) && filemtime($filename) + 86400 > time()) { // 86400 - 1 day in seconds
66-
$version = unserialize(file_get_contents($filename));
67-
$public = "-----BEGIN PUBLIC KEY-----
68-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwqWOVuF5uw7/+Z70djoK
69-
RlHIZFZPO0uYRezq90+7Amk+FDNd7KkL5eDve+vHRJBLAszF/7XKXe11xwliIsFs
70-
DFWQlsABVZB3oisKCBEuI71J4kPH8dKGEWR9jDHFw3cWmoH3PmqImX6FISWbG3B8
71-
h7FIx3jEaw5ckVPVTeo5JRm/1DZzJxjyDenXvBQ/6o9DgZKeNDgxwKzH+sw9/YCO
72-
jHnq1cFpOIISzARlrHMa/43YfeNRAm/tsBXjSxembBPo7aQZLAWHmaj5+K19H10B
73-
nCpz9Y++cipkVEiKRGih4ZEvjoFysEOdRLj6WiD/uUNky4xGeA6LaJqh5XpkFkcQ
74-
fQIDAQAB
75-
-----END PUBLIC KEY-----
76-
";
77-
if (openssl_verify($version["version"], base64_decode($version["signature"]), $public) == 1) {
78-
$_COOKIE["adminer_version"] = $version["version"]; // doesn't need to send to the browser
79-
}
80-
}
8165
echo script("mixin(document.body, {onkeydown: bodyKeydown, onclick: bodyClick"
82-
. (isset($_COOKIE["adminer_version"]) ? "" : ", onload: partial(verifyVersion, '" . VERSION . "', '" . js_escape(ME) . "', '" . get_token() . "')")
66+
. (isset($_COOKIE["adminer_version"]) ? "" : ", onload: partial(verifyVersion, '" . VERSION . "')")
8367
. "});
8468
document.body.classList.replace('nojs', 'js');
8569
const offlineMessage = '" . js_escape(lang('You are offline.')) . "';
@@ -153,8 +137,8 @@ function csp(): array {
153137
return array(
154138
array(
155139
"script-src" => "'self' 'unsafe-inline' 'nonce-" . get_nonce() . "' 'strict-dynamic'", // 'self' is a fallback for browsers not supporting 'strict-dynamic', 'unsafe-inline' is a fallback for browsers not supporting 'nonce-'
156-
"connect-src" => "'self'",
157-
"frame-src" => "https://www.adminer.org",
140+
"connect-src" => "'self' https://www.adminer.org",
141+
"frame-src" => "'none'",
158142
"object-src" => "'none'",
159143
"base-uri" => "'none'",
160144
"form-action" => "'self'",

adminer/static/functions.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,15 @@ function cookie(assign, days) {
9696

9797
/** Verify current Adminer version
9898
* @param string
99-
* @param string own URL base
100-
* @param string
10199
*/
102-
function verifyVersion(current, url, token) {
100+
function verifyVersion(current) {
103101
cookie('adminer_version=0', 1);
104-
const iframe = document.createElement('iframe');
105-
iframe.src = 'https://www.adminer.org/version/?current=' + current;
106-
iframe.frameBorder = 0;
107-
iframe.marginHeight = 0;
108-
iframe.scrolling = 'no';
109-
iframe.style.width = '7ex';
110-
iframe.style.height = '1.25em';
111-
iframe.style.display = 'none';
112-
addEventListener('message', event => {
113-
if (event.origin == 'https://www.adminer.org') {
114-
const match = /version=(.+)/.exec(event.data);
115-
if (match) {
116-
cookie('adminer_version=' + match[1], 1);
117-
ajax(url + 'script=version', () => { }, event.data + '&token=' + token);
118-
}
119-
}
120-
}, false);
121-
qs('#version').appendChild(iframe);
102+
// do not send X-Requested-With to avoid preflight
103+
fetch('https://www.adminer.org/version/?current=' + current).then(async response => {
104+
const json = await response.json();
105+
cookie('adminer_version=' + (json.version || current), 7); // empty if there's no newer version
106+
qs('#version').textContent = json.version;
107+
});
122108
}
123109

124110
/** Get value of select

plugins/version-github.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ class AdminerVersionGithub extends Adminer\Plugin {
1111
function head($dark = null) {
1212
?>
1313
<script <?php echo Adminer\nonce(); ?>>
14-
verifyVersion = (current, url, token) => {
14+
verifyVersion = current => {
1515
// dummy value to prevent repeated verifications after AJAX failure
1616
cookie('adminer_version=0', 1);
1717
ajax('https://api.github.com/repos/vrana/adminer/releases/latest', request => {
1818
const response = JSON.parse(request.responseText);
1919
const version = response.tag_name.replace(/^v/, '');
20-
// we don't save to adminer.version because the response is not signed; also GitHub can handle our volume of requests
2120
// we don't display the version here because we don't have version_compare(); design.inc.php will display it on the next load
2221
cookie('adminer_version=' + version, 1);
2322
}, null, null);

0 commit comments

Comments
 (0)