From 33b91a75132a7d708f9f67a508a8664d22a636bf Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 13 May 2021 16:23:28 +0200 Subject: [PATCH] set password cookie expiration --- copyparty/httpcli.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index e9bafd18..3b0e16aa 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -654,13 +654,16 @@ class HttpCli(object): if pwd in self.auth.iuser: msg = "login ok" + dt = datetime.utcfromtimestamp(time.time() + 60 * 60 * 24 * 365) + exp = dt.strftime("%a, %d %b %Y %H:%M:%S GMT") else: msg = "naw dude" pwd = "x" # nosec + exp = "Fri, 15 Aug 1997 01:00:00 GMT" - h = {"Set-Cookie": "cppwd={}; Path=/; SameSite=Lax".format(pwd)} + ck = "cppwd={}; Path=/; Expires={}; SameSite=Lax".format(pwd, exp) html = self.j2("msg", h1=msg, h2='ack', redir="/") - self.reply(html.encode("utf-8"), headers=h) + self.reply(html.encode("utf-8"), headers={"Set-Cookie": ck}) return True def handle_mkdir(self): @@ -939,13 +942,14 @@ class HttpCli(object): return True def _chk_lastmod(self, file_ts): + date_fmt = "%a, %d %b %Y %H:%M:%S GMT" file_dt = datetime.utcfromtimestamp(file_ts) - file_lastmod = file_dt.strftime("%a, %d %b %Y %H:%M:%S GMT") + file_lastmod = file_dt.strftime(date_fmt) cli_lastmod = self.headers.get("if-modified-since") if cli_lastmod: try: - cli_dt = time.strptime(cli_lastmod, "%a, %d %b %Y %H:%M:%S GMT") + cli_dt = time.strptime(cli_lastmod, date_fmt) cli_ts = calendar.timegm(cli_dt) return file_lastmod, int(file_ts) > int(cli_ts) except Exception as ex: