don't scrub uid when sending to client

This commit is contained in:
Sam Ginn 2017-01-23 01:18:47 -08:00
parent 8cec892fa5
commit 794e827526
1 changed files with 8 additions and 22 deletions

View File

@ -42,8 +42,7 @@ A client can make the following socket requests:
filename.
- "upvote": {"uid": UID, "id": ID}
a user can upvote another user's struct by passing in the struct's
uid (the scrub_uid() of the user who submitted it) and the id of
the struct itself.
uid and the id of the struct itself.
- "share": {"struct": STRUCT}
a user can share a struct and it will be saved to their directory
@ -125,19 +124,6 @@ def current_unix_time():
return int(time.time())
def scrub_uid(uid):
"""We don't want to reveal other users' full session_id's to other users,
so we hide it by just sending the first 8 characters.
NB: We use the session_id as the sole source of truth for authentication
and logging purposes - if it was leaked, other turkers would be able to
impersonate users.
TODO: Convert to using signed JWTs.
"""
return uid[:8]
def emit_structs():
"""Walk through the STRUCTS_FOLDER directory and read each struct and emit
it to the user one by one."""
@ -158,7 +144,7 @@ def emit_structs():
struct = json.loads(lines[2].strip())
score = score_struct(timestamp, len(upvotes))
message = {"uid": uid, "id": str(fname), "score": score, "upvotes": [scrub_uid(up) for up in upvotes], "struct": struct}
message = {"uid": uid, "id": str(fname), "score": score, "upvotes": [up for up in upvotes], "struct": struct}
emit("struct", message)
except:
pass
@ -188,7 +174,7 @@ def emit_utterances():
latest_5[earliest_idx] = file_info
for (time, uid, path) in sorted(latest_5, key=lambda s: int(s[0]), reverse=True):
uid = scrub_uid(uid)
uid = uid
utts = []
count = 0
for line in reverse_readline(path):
@ -252,7 +238,7 @@ def handle_share(data):
current score of the struct and ID is the unique index (auto-incremented) of
this particular struct.."""
user_structs_folder = os.path.join(STRUCTS_FOLDER, scrub_uid(session.uid))
user_structs_folder = os.path.join(STRUCTS_FOLDER, session.uid)
make_dir_if_necessary(user_structs_folder)
names = os.listdir(user_structs_folder)
new_struct_id = "1"
@ -270,7 +256,7 @@ def handle_share(data):
f.write(json.dumps(data["struct"])) # the actual struct
# Broadcast addition to the "community" room
message = {"uid": scrub_uid(session.uid), "id": new_struct_id, "score": score, "upvotes": [], "struct": data["struct"]}
message = {"uid": session.uid, "id": new_struct_id, "score": score, "upvotes": [], "struct": data["struct"]}
emit("struct", message, broadcast=True, room="community")
@ -319,7 +305,7 @@ def upvote(data):
score = score_struct(timestamp, len(upvotes))
# and then broadcast the new upvote to the room:
message = {"uid": data["uid"], "id": data["id"], "up": scrub_uid(session.uid), "score": score}
message = {"uid": data["uid"], "id": data["id"], "up": session.uid, "score": score}
emit("upvote", message, broadcast=True, room="community")
@ -339,10 +325,10 @@ def handle_log(data):
# If the message is an accept or define type, broadcast it to all
# community-connected clients so they can update their display.
if data["type"] == "accept":
emit("new_accept", {"uid": scrub_uid(session.uid), "query": data["msg"]["query"], "timestamp": current_unix_time()},
emit("new_accept", {"uid": session.uid, "query": data["msg"]["query"], "timestamp": current_unix_time()},
broadcast=True, room="community")
elif data["type"] == "define":
emit("new_define", {"uid": scrub_uid(session.uid), "defined": data["msg"]["defineAs"], "timestamp": current_unix_time()},
emit("new_define", {"uid": session.uid, "defined": data["msg"]["defineAs"], "timestamp": current_unix_time()},
broadcast=True, room="community")