Skip to content
Browse files

Implement domain bans that inform user of block at submit time.

  • Loading branch information...
1 parent dbaa48e commit 44ebdeb378f4bf09d6bd1f395764868b57d9fd82 @spladug spladug committed
11 r2/r2/controllers/
@@ -187,6 +187,7 @@ def POST_compose(self, form, jquery, to, subject, body, ip):
VRatelimit(rate_user = True, rate_ip = True,
prefix = "rate_submit_"),
+ VShamedDomain('url'),
ip = ValidIP(),
sr = VSubmitSR('sr', 'kind'),
url = VUrl(['url', 'sr', 'resubmit']),
@@ -248,7 +249,8 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,
check_domain = True
# check for no url, or clear that error field on return
- if form.has_errors("url", errors.NO_URL, errors.BAD_URL):
+ if form.has_errors("url", errors.NO_URL, errors.BAD_URL,
+ errors.DOMAIN_BANNED):
elif form.has_errors("url", errors.ALREADY_SUB):
check_domain = False
@@ -266,13 +268,8 @@ def POST_submit(self, form, jquery, url, selftext, kind, title,
g.log.warning("%s is trying to submit url=None (title: %r)"
% (request.ip, title))
elif check_domain:
- banmsg = is_banned_domain(url, request.ip)
-# Uncomment if we want to let spammers know we're on to them
-# if banmsg:
-# form.set_html(".field-url.BAD_URL", banmsg)
-# return
+ banmsg = is_banned_domain(url, request.ip)
form.has_errors('text', errors.TOO_LONG)
1 r2/r2/controllers/
@@ -94,6 +94,7 @@
('OAUTH2_ACCESS_DENIED', _('access denied by the user')),
('CONFIRM', _("please confirm the form")),
('NO_API', _('cannot perform this action via the API')),
+ ('DOMAIN_BANNED', _('%(domain)s is not allowed on reddit: %(reason)s')),
errors = Storage([(e, e) for e in error_list.keys()])
11 r2/r2/controllers/validator/
@@ -1025,6 +1025,17 @@ def param_docs(self):
return params
+class VShamedDomain(Validator):
+ def run(self, url):
+ if not url:
+ return
+ is_shamed, domain, reason = is_shamed_domain(url, request.ip)
+ if is_shamed:
+ self.set_error(errors.DOMAIN_BANNED, dict(domain=domain,
+ reason=reason))
class VExistingUname(VRequired):
def __init__(self, item, *a, **kw):
VRequired.__init__(self, item, errors.NO_USER, *a, **kw)
3 r2/r2/models/
@@ -329,6 +329,9 @@ def is_banned_IP(ip):
def is_banned_domain(dom, ip):
return None
+def is_shamed_domain(dom, ip):
+ return False, None, None
def valid_thing(v, karma, *a, **kw):
return not v._thing1._spam
1 r2/r2/templates/newlink.html
@@ -72,6 +72,7 @@
<input id="url" name="url" type="text" value="${thing.url}"/>
${error_field("NO_URL", "url", "div")}
${error_field("BAD_URL", "url", "div")}
+ ${error_field("DOMAIN_BANNED", "url", "div")}
${error_field("ALREADY_SUB", "url", "div")}
${error_field("NO_LINKS", "sr")}
${error_field("NO_SELFS", "sr")}

1 comment on commit 44ebdeb


Instead of banning link shorteners why not follow the link and pull the rel="canonical" from the page, then use that link? Why not do this too for all pages?

Please sign in to comment.
Something went wrong with that request. Please try again.