File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 2020
2121import datetime
2222import subprocess
23+ from hmac import HMAC , compare_digest
24+ from hashlib import sha256
2325from typing import Dict , Optional , Union
2426
2527import psutil
@@ -245,7 +247,19 @@ async def get_server_stats(request: MystbinRequest):
245247@router .get ("/admin/release_hook" , tags = ["admin" ], include_in_schema = False )
246248@limit ("admin" )
247249async def release_hook (request : MystbinRequest ):
248- if not request .state .user or not request .state .user ["admin" ]:
250+
251+ config = pathlib .Path ("config.json" )
252+ if not config .exists ():
253+ config = pathlib .Path ("../../config.json" )
254+
255+ with open (config ) as f :
256+ config : Dict [str , Dict [str , Any ]] = ujson .load (f )
257+
258+ SECRET = config ['github_secret' ].encode ()
259+
260+ received_sign = request .headers .get ('X-Hub-Signature-256' ).split ('sha256=' )[- 1 ].strip ()
261+ expected_sign = HMAC (key = SECRET , msg = (await request .data ), digestmod = sha256 ).hexdigest ()
262+ if not compare_digest (received_sign , expected_sign ):
249263 return UJSONResponse ({"error" : "Unauthorized" }, status_code = 401 )
250264
251265 command = 'cd /root/MystBin/; git pull;'
You can’t perform that action at this time.
0 commit comments