ignore plugins with \x00 in name

This commit is contained in:
j 2018-07-09 17:21:28 +02:00
parent 113594915a
commit 190e07ef90
2 changed files with 20 additions and 0 deletions

View file

@ -6,6 +6,20 @@ import django.contrib.postgres.fields.jsonb
from django.db import migrations, models from django.db import migrations, models
def cleanup_sessiondata(apps, schema_editor):
SessionData = apps.get_model("user", "SessionData")
for data in SessionData.objects.all():
changed = False
plugins = []
for p in data.info.get('navigator', {}).get('plugins', []):
if p and '\x00' not in p:
plugins.append(p)
else:
changed = True
if changed:
data.info['navigator']['plugins'] = plugins
data.save()
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
@ -13,6 +27,7 @@ class Migration(migrations.Migration):
] ]
operations = [ operations = [
migrations.RunPython(cleanup_sessiondata),
migrations.RunSQL( migrations.RunSQL(
'ALTER TABLE "user_sessiondata" ALTER COLUMN "info" TYPE jsonb USING "info"::text::jsonb' 'ALTER TABLE "user_sessiondata" ALTER COLUMN "info" TYPE jsonb USING "info"::text::jsonb'
), ),

View file

@ -111,6 +111,11 @@ class SessionData(models.Model):
info = json.loads(request.POST.get('data', '{}')) info = json.loads(request.POST.get('data', '{}'))
if info and isinstance(info, dict): if info and isinstance(info, dict):
data.info = info data.info = info
if data.info.get('navigator', {}).get('plugins'):
data.info['navigator']['plugins'] = [
p for p in data.info['navigator']['plugins']
if p and '\x00' not in p
]
screen = data.info.get('screen', {}) screen = data.info.get('screen', {})
if screen and 'height' in screen and 'width' in screen: if screen and 'height' in screen and 'width' in screen:
data.screensize = u'%s\xd7%s' % (screen['width'], screen['height']) data.screensize = u'%s\xd7%s' % (screen['width'], screen['height'])