Browse Source

Add hidden nonce (honeypot) field to filter bot autofills on subs page

Kailash Nadh 4 years ago
parent
commit
fe61e898a3
3 changed files with 13 additions and 0 deletions
  1. 8 0
      cmd/public.go
  2. 3 0
      static/public/static/style.css
  3. 2 0
      static/public/templates/subscription-form.html

+ 8 - 0
cmd/public.go

@@ -302,6 +302,14 @@ func handleSubscriptionForm(c echo.Context) error {
 		return err
 	}
 
+	// If there's a nonce value, a bot could've filled the form.
+	if c.FormValue("nonce") != "" {
+		return c.Render(http.StatusOK, tplMessage,
+			makeMsgTpl(app.i18n.T("public.errorTitle"), "",
+				app.i18n.T("public.invalidFeature")))
+
+	}
+
 	if len(req.SubListUUIDs) == 0 {
 		return c.Render(http.StatusBadRequest, tplMessage,
 			makeMsgTpl(app.i18n.T("public.errorTitle"), "",

+ 3 - 0
static/public/static/style.css

@@ -274,6 +274,9 @@ input[type="text"], input[type="email"], select {
 .form .lists {
   margin-top: 45px;
 }
+  .form .nonce {
+    display: none;
+  }
 
 .footer {
   text-align: center;

+ 2 - 0
static/public/templates/subscription-form.html

@@ -8,6 +8,8 @@
             <p>
                 <label>{{ L.T "subscribers.email" }}</label>
                 <input name="email" required="true" type="email" placeholder="{{ L.T "subscribers.email" }}" autofocus="true" >
+
+                <input name="nonce" class="nonce" value="" />
             </p>
             <p>
                 <label>{{ L.T "public.subName" }}</label>