Skip to content

Commit 1571a18

Browse files
committed
Anti NFT Spam Bot - reject URLs with a hostname with no period in it
1 parent d31bd0c commit 1571a18

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

anti_nft_spam_bot/src/sanitized_url.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,24 @@ impl SanitizedUrl {
9696
static CAN_BE_A_BASE: &str =
9797
"URL shouldn't be cannot-be-a-base due to check at start of function";
9898

99-
if url.scheme() == "file" || !url.has_host() || url.cannot_be_a_base() {
99+
// Reject a bunch of weird URLs.
100+
if url.scheme() == "file" || url.cannot_be_a_base() {
100101
return None;
101102
}
103+
104+
if let Some(host) = url.host() {
105+
if let Host::Domain(d) = host {
106+
if !d.contains('.') {
107+
// If host is a hostname and has no period, then it's probably not a world wide web
108+
// link that could poossibly be a spam.
109+
return None;
110+
}
111+
}
112+
} else {
113+
// No host, no pass.
114+
return None;
115+
}
116+
102117
if url.scheme() != "https" {
103118
// This discards a bunch of weird, likely invalid URLs while we're at it.
104119
url.set_scheme("https").ok()?;
@@ -707,4 +722,10 @@ mod tests {
707722
);
708723
assert_eq!(url.destructure_to_number(8), None);
709724
}
725+
726+
#[test]
727+
fn reject_with_no_period() {
728+
let url = Url::parse("https://what/").unwrap();
729+
assert_eq!(SanitizedUrl::new(url), None);
730+
}
710731
}

0 commit comments

Comments
 (0)