大丈夫
- 稍早前修改了session相关代码,引入一个小bug,导致极少数用户串session(体现为登陆后进入他人账号)。
- 收到用户反馈后,临时关站并于5min内修复问题,现已重新开放,所有用户将被登出,请被登出的用户重新登入。
- 用户的密码仍然是安全的,并没有泄露或被篡改,不需要修改密码。
- 该bug造成的所有影响已消除。期间用户的帖子可能有极小部分被误删,请自行恢复。如果帖子被他人编辑内容,请私信联系 @thphd 恢复。
thphd
thphd2047前站长 from itsdangerous import Signer from base64 import b64encode,b64decode ... # rough implementation of JSON Web Signature (JWS) def signj(json_object): # object -> utf8str json_str = json.dumps(json_object) json_bin = json_str.encode('utf-8') json_bin_b64 = b64encode(json_bin) json_bin_b64_signed_bin = signer.sign(json_bin_b64) json_bin_b64_signed_str = json_bin_b64_signed_bin.decode('utf-8') return json_bin_b64_signed_str def unsignj(json_bin_b64_signed_str): # utf8str -> object try: json_bin_b64_signed_bin = json_bin_b64_signed_str.encode('utf-8') json_bin_b64 = signer.unsign(json_bin_b64_signed_bin) json_bin = b64decode(json_bin_b64) json_str = json_bin.decode('utf-8') json_object = json.loads(json_str) return json_object except Exception as e: log_err('unsign err', e) return {} def save_session(resp): curr_sess_string = get_current_session_str() newly_signed_sess_string = signj(g.session) if newly_signed_sess_string != curr_sess_string: qprint('save_session', g.session) resp.set_cookie( key='session', value=newly_signed_sess_string, max_age=86400*31, httponly=True, samesite='strict', ) def load_session(): css = get_current_session_str() if css: return unsignj(css) else: return {} def get_current_session_str(): return request.cookies.get('session', default='')caching
unsignj()is problematic since dictionaries are mutable.thphd2047前站长 unsignj()takes a cryptographically signed session string and returns a dict in a deterministic fashion. however, if you cache this function and modify the returned dict, later calls to this function with the same arguments will start returning the modified dict, instead of a fresh copy.when a user first visits our site, his session string is usually empty. if we pass that empty string to a cached version of
unsignj, it will start returning the SAME empty dict whenever the input is an empty string. which means, if you weren't alrealy logged in, you'll share a session object with anyone who also weren't logged in. After person A login into account A (by writing hisuidinto the dict), everyone who weren't logged in will find themselves using account A.solution:
return cached_unsignj().copy()thphd2047前站长 modified(current) version:
def unsignj(json_bin_b64_signed_str): return unsignj_cached(json_bin_b64_signed_str).copy() @lru_cache(maxsize=4096) def unsignj_cached(json_bin_b64_signed_str): # utf8str -> object json_bin_b64_signed_bin = json_bin_b64_signed_str.encode('utf-8') json_bin_b64 = signer.unsign(json_bin_b64_signed_bin) json_bin = b64decode(json_bin_b64) json_str = json_bin.decode('utf-8') json_object = json.loads(json_str) return json_object def load_session(): css = get_current_session_str() if not css: return {} try: return unsignj(css) except Exception as e: print_err('unsign err', e) return {}7站女鬼 大家好,我是7站女鬼。
我脾气大,气量小,爱颐气指使,喜欢封号,但是大家都喜欢我。 我是清华博士,技术很棒。品葱一次就被攻破了,我们被阿篱攻击两次,依然毫发无损,对方只会利用我写出的bug来捣乱。
大家要相信我的技术。紧密跟随者以7站女鬼为中心,高喊:7或又赢。