Skip to content

Commit

Permalink
修复webhook验证问题
Browse files Browse the repository at this point in the history
  • Loading branch information
nkxingxh committed Aug 17, 2021
1 parent 9effd38 commit 539f8a4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$_DATA = json_decode(file_get_contents("php://input"), true);
saveFile('webhook.log', file_get_contents("php://input"));

if (!empty(Authorization) && (empty($_SERVER['HTTP_AUTHORIZATION']) || $_SERVER['HTTP_AUTHORIZATION'] != Authorization)) {
if (!verifyAuthorization()) {
header('HTTP/1.1 403 Forbidden');
exit;
}
Expand Down Expand Up @@ -83,7 +83,7 @@ function checkUpdates($_DATA)
}
if (compareVersions(version, $resp['tag_name']) == '<')
sendFriendMessage(admin_qq, "miraiez 发现新版本\n当前版本:" . version . "\n最新版本:" . $resp['tag_name']);
elseif($_DATA['type'] == 'FriendMessage') replyMessage("当前已经是最新版本");
elseif ($_DATA['type'] == 'FriendMessage') replyMessage("当前已经是最新版本");
}

function compareVersions($ver1, $ver2)
Expand All @@ -98,3 +98,10 @@ function compareVersions($ver1, $ver2)
return compareVersions($ver1, $ver2);
}
}

function verifyAuthorization()
{
if (empty(Authorization)) return true;
if (empty($_SERVER['HTTP_AUTHORIZATION'])) return false;
return (('[' . Authorization . ']') == $_SERVER['HTTP_AUTHORIZATION']) || (Authorization == $_SERVER['HTTP_AUTHORIZATION']);
}

0 comments on commit 539f8a4

Please sign in to comment.