From patchwork Tue Sep 8 14:06:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Bracht Laumann Jespersen X-Patchwork-Id: 1359745 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm6SL1c4Yz9sTW for ; Wed, 9 Sep 2020 00:08:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=laumann.xyz Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=laumann.xyz header.i=@laumann.xyz header.a=rsa-sha256 header.s=fm1 header.b=dsGRFL/v; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=urPDmNPq; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4Bm6SK4slvzDqS9 for ; Wed, 9 Sep 2020 00:08:17 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=laumann.xyz (client-ip=64.147.123.21; helo=wout5-smtp.messagingengine.com; envelope-from=t@laumann.xyz; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=laumann.xyz Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=laumann.xyz header.i=@laumann.xyz header.a=rsa-sha256 header.s=fm1 header.b=dsGRFL/v; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=urPDmNPq; dkim-atps=neutral Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4Bm6SC6Lg9zDqRH for ; Wed, 9 Sep 2020 00:08:10 +1000 (AEST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 4C758C36; Tue, 8 Sep 2020 10:08:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 08 Sep 2020 10:08:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=laumann.xyz; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm1; bh=URyHSaRGaV6MHfJlmQrRmvr/r/ zYz9bdMRih4MigLBs=; b=dsGRFL/vmranFqT308SB8Ss8YF43m8QPFbRamn10JK HJtHeX6QaSeQnaG70hF9c8KymSMprcIs20xHElXmfmL2QI2RhTEx676Xp9WlGpcZ H17pkYrU3Q85L4R5bhn7FLL0n/rZd9GKiqTn8XohKAFGbOQ+9agmSjKgn58xY7+p PomuhukMJpgkthOtQKSn6HIB8gSNS8FjDVboCUfb9GvkRp5aJKiIuHzL1dJt297L rLcD0nipDQu1iZ9uZol6ygDdOoxWDvQT6q+ygQzIFqsSe3oWGqlvIdnQkBGePTrq MMqp5L7cHaFfshuK1W/tJDkH5KdNj4IUVEvyvLZOFS2w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=URyHSaRGaV6MHfJlm QrRmvr/r/zYz9bdMRih4MigLBs=; b=urPDmNPqWj6zsD0LHT+uOv9fWRBTDPQgh o2CwUw1ccozRWA1i4QF9Uxc681rsCVVvnQS5qAgpLINHbh/QaOVb2wHsryUWpBfu 0eBWJAiNiPs3oHJUFY8M6uWaIWIAE/fC6ZoDV7CeGz/7yiXtN4QE3M45bIapCdpP PiqIE1twhExNjasnpZNMKlGh4uXZ9nuu8QdLZm4X/KLLJnhZrCVljh+/oqSj7W99 TfPb4ux3l6coJ5lz640RiOhp4vOWKt4L8NrUsmjppP3aXWuZTQjJScUJ1trdNXgr gETuYDXssImfVdS2gYxblww9yybOwkBMz6luBj7JIDiIqRE/RmyKg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduiedrudehfedgheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfeehmdenucfjughrpefhvf fufffkofgggfestdekredtredttdenucfhrhhomhepvfhhohhmrghsuceurhgrtghhthcu nfgruhhmrghnnhculfgvshhpvghrshgvnhcuoehtsehlrghumhgrnhhnrdighiiiqeenuc ggtffrrghtthgvrhhnpeeifeeftdffieevveevhefhgfehueelhfelleeiffegtdejledv jeejvefffeekhfenucffohhmrghinhepshhrrdhhthenucfkphepkedtrdejuddrudegvd druddvieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehtsehlrghumhgrnhhnrdighiii X-ME-Proxy: Received: from localhost.localdomain (unknown [80.71.142.126]) by mail.messagingengine.com (Postfix) with ESMTPA id 4DFF53064605; Tue, 8 Sep 2020 10:08:07 -0400 (EDT) From: Thomas Bracht Laumann Jespersen To: patchwork@lists.ozlabs.org Subject: [PATCH v2] models: Validate Project.linkname does not contain forward slash Date: Tue, 8 Sep 2020 16:06:08 +0200 Message-Id: <20200908140606.26224-1-t@laumann.xyz> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" I started by creating a project that contained a forward slash (importing patches from https://lists.sr.ht/~sircmpwn/sr.ht-dev/) and it fails to render the "projects" main page. The specific error reads: NoReverseMatch at / Reverse for 'patch-list' with keyword arguments '{'project_id': 'foo/bar'}' not found. 1 pattern(s) tried: ['project/(?P[^/]+)/list/$'] which appears to explicitly disallow forward slashes. So I think it makes sense to validate that project linkname doesn't contain forward slahes. Signed-off-by: Thomas Bracht Laumann Jespersen --- I simplified the check for '/' as suggested, and got the pre-commit hook to work. I changed the formatting in the migration to satisfy the max line length check. .../0044_add_project_linkname_validation.py | 23 +++++++++++++++++++ patchwork/models.py | 10 +++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 patchwork/migrations/0044_add_project_linkname_validation.py diff --git a/patchwork/migrations/0044_add_project_linkname_validation.py b/patchwork/migrations/0044_add_project_linkname_validation.py new file mode 100644 index 0000000..8add430 --- /dev/null +++ b/patchwork/migrations/0044_add_project_linkname_validation.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.10 on 2020-09-06 22:47 + +from django.db import migrations, models +import patchwork.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('patchwork', '0043_merge_patch_submission'), + ] + + operations = [ + migrations.AlterField( + model_name='project', + name='linkname', + field=models.CharField( + max_length=255, + unique=True, + validators=[patchwork.models.validate_project_linkname] + ), + ), + ] diff --git a/patchwork/models.py b/patchwork/models.py index 77ab924..64d5a10 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -31,6 +31,13 @@ def validate_regex_compiles(regex_string): raise ValidationError('Invalid regular expression entered!') +def validate_project_linkname(linkname): + if '/' in linkname: + raise ValidationError( + 'Invalid project linkname: Value cannot contain forward slash (/)' + ) + + class Person(models.Model): # properties @@ -56,7 +63,8 @@ class Person(models.Model): class Project(models.Model): # properties - linkname = models.CharField(max_length=255, unique=True) + linkname = models.CharField(max_length=255, unique=True, + validators=[validate_project_linkname]) name = models.CharField(max_length=255, unique=True) listid = models.CharField(max_length=255) listemail = models.CharField(max_length=200)