Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Hashing sensible information in cookies, request_url and referer. #494

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/adhocracy/lib/importexport/transforms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import datetime
import re
import hashlib

from adhocracy.lib import votedetail
from adhocracy import model
Expand Down Expand Up @@ -439,12 +440,31 @@ class RequestLogTransform(_Transform):

def __init__(self, options):
super(RequestLogTransform, self).__init__(options)
self.hash_func = hashlib.sha1

def _export(self, obj):
res = obj.to_dict()

res['access_time'] = encode_time(res['access_time'])

# Filter out session codes from adhocracy login cookie
res['cookies'] = re.sub(r'(adhocracy_login\=)("?[a-f0-9]{40})',
lambda m: m.group(1) + self.hash_func(m.group(2)).hexdigest(),
res['cookies'])

# Filter out welcome codes
res['request_url'] = self._url_filter(res['request_url'])
res['referer'] = self._url_filter(res['referer'])

return res

def _url_filter(self, url):
if url is not None:
url = re.sub(r'(/welcome/[^/]+/)([0-9a-f]+)(?=/|\?|$)',
lambda m: m.group(1) + self.hash_func(m.group(2)).hexdigest(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cuts off the part after the welcome code. Is this intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What make you think so?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I misunderstood what re.sub does.

url)
return url


class StaticPageTransform(_Transform):
def __init__(self, options, backend=None):
Expand Down