Skip to content

Commit 616a02a

Browse files
committed
Make antispam-protected links also be javascript-triggered
This makes a tiny javascript run to convert it into a POST and then receive that POST. The idea behind this is to remove the links from view of crawlers (hello AI bots!) that completely ignore robots.txt, causing lots of redirect chains on account of logins. We still allow GET requests on those endpoints, as there are external links pointing to them as well as people having scripts. But those are at least to fewer emails than all.
1 parent 8323c9d commit 616a02a

File tree

6 files changed

+17
-3
lines changed

6 files changed

+17
-3
lines changed

django/archives/mailarchives/templates/_message.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
<tr>
3131
<th class="align-middle" scope="row">Views:</th>
3232
<td>
33-
<a href="/message-id/raw/{{msg.messageid|urlencode}}">Raw Message</a> |
3433
<a href="/message-id/flat/{{msg.messageid|urlencode}}">Whole Thread</a> |
35-
<a href="/message-id/mbox/{{msg.messageid|urlencode}}">Download mbox</a>
36-
{%if allow_resend %}| <a href="/message-id/resend/{{msg.messageid|urlencode}}">Resend email</a>{%endif%}
34+
<a href="#" data-ref="/message-id/raw/{{msg.messageid|urlencode}}" class="post-link">Raw Message</a> |
35+
<a href="#" data-ref="/message-id/mbox/{{msg.messageid|urlencode}}" class="post-link">Download mbox</a>
36+
{%if allow_resend %} | <a href="#" data-ref="/message-id/resend/{{msg.messageid|urlencode}}" class="post-link">Resend email</a>{%endif%}
3737
</td>
3838
</tr>
3939
{% if not show_all %}

django/archives/mailarchives/templates/message.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
<h1 class="subject">{{msg.subject}}</h1>
77
{%endif%}
88
{% include '_message.html' with msg=msg lists=lists %}
9+
<form id="mail_other_options_form" method="post" action="/"></form>
910
{%endblock%}

django/archives/mailarchives/templates/message_flat.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ <h1 id="flatMsgSubject" class="subject" data-isfirst="{{isfirst}}" data-msgid="{
2323
<hr style="margin-bottom: 0.5rem;" />
2424
{% endif %}
2525
{%endfor%}
26+
<form id="mail_other_options_form" method="post" action="/"></form>
2627
{%endblock%}

django/archives/mailarchives/templates/message_resend.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ <h1 class="subject">Resend - {{msg.subject}}</h1>
1717

1818
<h4>Message to resend</h4>
1919
{% include '_message.html' with msg=msg lists=lists show_all=True %}
20+
<form id="mail_other_options_form" method="post" action="/"></form>
2021
{%endblock%}

django/archives/mailarchives/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ def message_flat(request, msgid):
547547
return r
548548

549549

550+
@csrf_exempt
550551
@nocache
551552
@antispam_auth
552553
def message_raw(request, msgid):
@@ -606,6 +607,7 @@ def _message_stream(first):
606607
return r
607608

608609

610+
@csrf_exempt
609611
@nocache
610612
@antispam_auth
611613
def message_mbox(request, msgid):
@@ -650,6 +652,7 @@ def mbox(request, listname, listname2, mboxyear, mboxmonth):
650652

651653

652654
@transaction.atomic
655+
@csrf_exempt
653656
def resend(request, messageid):
654657
if not settings.ALLOW_RESEND:
655658
raise PermissionDenied("Access denied.")

django/media/js/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ $(function(){
44
document.location.href = '/message-id/' + $(this).val();
55
});
66

7+
/* Callback for viewing protected versions */
8+
$('a.post-link').click(function(e) {
9+
if ($(this).data('ref')) {
10+
$('#mail_other_options_form').attr('action', $(this).data('ref'));
11+
$('#mail_other_options_form').submit();
12+
}
13+
});
14+
715

816
/*
917
* For flat message view, redirect to the anchor of the messageid we're watching,

0 commit comments

Comments
 (0)