From 644d32a4303778c1ad9ffcffe92a2e24b0fb742b Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 8 Jul 2021 18:52:26 +0000 Subject: [PATCH] Strip PGP signature from annotated tag message --- gitsrht/blueprints/repo.py | 14 ++++++++++++-- gitsrht/templates/ref.html | 2 +- gitsrht/templates/refs.html | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index a078fb8..9066544 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -495,6 +495,14 @@ def patch(owner, repo, ref): return "Error preparing patch", 500 return Response(subp.stdout, mimetype='text/plain') +def strip_pgp_signature(text): + if not text.strip().endswith("-----END PGP SIGNATURE-----"): + return text + i = text.rindex('-----BEGIN PGP SIGNATURE-----') + if i < 0: + return text + return text[:i] + @repo.route("///refs") def refs(owner, repo): owner, repo = get_repo_or_redir(owner, repo) @@ -546,7 +554,8 @@ def refs(owner, repo): owner=owner, repo=repo, tags=tags, branches=branches, git_repo=git_repo, isinstance=isinstance, pygit2=pygit2, page=page + 1, total_pages=total_pages, - default_branch=default_branch) + default_branch=default_branch, + strip_pgp_signature=strip_pgp_signature) @repo.route("///refs/rss.xml") @@ -593,4 +602,5 @@ def ref(owner, repo, ref): .filter(Artifact.commit == tag.target.hex)).all() return render_template("ref.html", view="refs", owner=owner, repo=repo, git_repo=git_repo, tag=tag, - artifacts=artifacts, default_branch=git_repo.default_branch()) + artifacts=artifacts, default_branch=git_repo.default_branch(), + strip_pgp_signature=strip_pgp_signature) diff --git a/gitsrht/templates/ref.html b/gitsrht/templates/ref.html index 773c8c0..480b364 100644 --- a/gitsrht/templates/ref.html +++ b/gitsrht/templates/ref.html @@ -89,7 +89,7 @@
{% if tag.message %} -
{{tag.message}}
+
{{strip_pgp_signature(tag.message)}}
{% endif %}
diff --git a/gitsrht/templates/refs.html b/gitsrht/templates/refs.html index a9f369a..5aef23b 100644 --- a/gitsrht/templates/refs.html +++ b/gitsrht/templates/refs.html @@ -71,7 +71,7 @@ {% if tag.message %} -
{{tag.message}}
+
{{strip_pgp_signature(tag.message)}}
{% endif %} {% endfor %} -- 2.38.4