From 8b044523d572b82707be1afc23a9bd000a5f36e1 Mon Sep 17 00:00:00 2001 From: HgO Date: Wed, 26 Oct 2022 17:12:41 +0200 Subject: [PATCH] fix incorrect permissions on token file --- matrix_alertbot/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/matrix_alertbot/main.py b/matrix_alertbot/main.py index 88ae052..345e5d1 100644 --- a/matrix_alertbot/main.py +++ b/matrix_alertbot/main.py @@ -109,7 +109,13 @@ async def start_matrix_client( return False # Save user's access token and device ID - with open(config.user_token_file, "w") as ofd: + # See https://stackoverflow.com/a/45368120 + user_token_fd = os.open( + config.user_token_file, + flags=os.O_CREAT | os.O_WRONLY | os.O_TRUNC, + mode=0o640, + ) + with os.fdopen(user_token_fd, "w") as ofd: json.dump( { "device_id": login_response.device_id,