diff --git a/Cargo.lock b/Cargo.lock index ea1c9776f..dc70d330e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,9 +70,9 @@ dependencies = [ "log", "once_cell", "parking_lot", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.7", "smallvec", - "tokio 1.7.1", + "tokio 1.8.0", "tokio-util 0.6.7", ] @@ -218,7 +218,7 @@ checksum = "bc7d7cd957c9ed92288a7c3c96af81fa5291f65247a76a34dac7b6af74e52ba0" dependencies = [ "actix-macros 0.2.1", "futures-core", - "tokio 1.7.1", + "tokio 1.8.0", ] [[package]] @@ -548,7 +548,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "tokio 1.7.1", + "tokio 1.8.0", "uuid", ] @@ -567,7 +567,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "tokio 1.7.1", + "tokio 1.8.0", "uuid", ] @@ -1206,7 +1206,7 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ad9169582543d2cfe9961be1e9eaf4fc42f9aa3483f7c485717b8dde36466ea" dependencies = [ - "hashbrown", + "hashbrown 0.9.1", ] [[package]] @@ -1370,7 +1370,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.7", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -1477,7 +1477,7 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 1.7.1", + "tokio 1.8.0", "tokio-util 0.6.7", "tracing", ] @@ -1491,6 +1491,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "heck" version = "0.3.3" @@ -1502,9 +1508,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -1545,7 +1551,7 @@ checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" dependencies = [ "bytes 1.0.1", "http", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.7", ] [[package]] @@ -1591,7 +1597,7 @@ dependencies = [ "reqwest", "sha2", "thiserror", - "tokio 1.7.1", + "tokio 1.8.0", ] [[package]] @@ -1628,9 +1634,9 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.7", "socket2 0.4.0", - "tokio 1.7.1", + "tokio 1.8.0", "tower-service", "tracing", "want", @@ -1645,7 +1651,7 @@ dependencies = [ "bytes 1.0.1", "hyper", "native-tls", - "tokio 1.7.1", + "tokio 1.8.0", "tokio-native-tls", ] @@ -1687,12 +1693,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.2" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.11.2", ] [[package]] @@ -1840,7 +1846,7 @@ dependencies = [ "strum", "strum_macros", "thiserror", - "tokio 1.7.1", + "tokio 1.8.0", "url", "uuid", ] @@ -1903,7 +1909,7 @@ dependencies = [ "strum", "strum_macros", "thiserror", - "tokio 1.7.1", + "tokio 1.8.0", "url", "uuid", ] @@ -1950,7 +1956,7 @@ dependencies = [ "strum", "strum_macros", "thiserror", - "tokio 1.7.1", + "tokio 1.8.0", "url", "uuid", ] @@ -1995,7 +2001,7 @@ dependencies = [ "strum", "strum_macros", "thiserror", - "tokio 1.7.1", + "tokio 1.8.0", "url", ] @@ -2129,7 +2135,7 @@ dependencies = [ "serde", "serde_json", "strum", - "tokio 1.7.1", + "tokio 1.8.0", "url", ] @@ -2163,7 +2169,7 @@ dependencies = [ "strum", "strum_macros", "thiserror", - "tokio 1.7.1", + "tokio 1.8.0", "url", ] @@ -2189,7 +2195,7 @@ dependencies = [ "serde_json", "strum", "strum_macros", - "tokio 1.7.1", + "tokio 1.8.0", ] [[package]] @@ -2739,9 +2745,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" [[package]] name = "pin-utils" @@ -3056,11 +3062,11 @@ dependencies = [ "mime", "native-tls", "percent-encoding", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.7", "serde", "serde_json", "serde_urlencoded", - "tokio 1.7.1", + "tokio 1.8.0", "tokio-native-tls", "url", "wasm-bindgen", @@ -3537,18 +3543,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa6f76457f59514c7eeb4e59d891395fab0b2fd1d40723ae737d64153392e9c6" +checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a36768c0fbf1bb15eca10defa29526bda730a2376c2ab4393ccfa16fb1a318d" +checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745" dependencies = [ "proc-macro2 1.0.27", "quote 1.0.9", @@ -3662,9 +3668,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb2ed024293bb19f7a5dc54fe83bf86532a44c12a2bb8ba40d64a4509395ca2" +checksum = "570c2eb13b3ab38208130eccd41be92520388791207fde783bda7c1e8ace28d4" dependencies = [ "autocfg", "bytes 1.0.1", @@ -3673,7 +3679,7 @@ dependencies = [ "mio 0.7.13", "once_cell", "parking_lot", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.7", "signal-hook-registry", "winapi 0.3.9", ] @@ -3685,7 +3691,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" dependencies = [ "native-tls", - "tokio 1.7.1", + "tokio 1.8.0", ] [[package]] @@ -3725,8 +3731,8 @@ dependencies = [ "futures-core", "futures-sink", "log", - "pin-project-lite 0.2.6", - "tokio 1.7.1", + "pin-project-lite 0.2.7", + "tokio 1.8.0", ] [[package]] @@ -3743,7 +3749,7 @@ checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.6", + "pin-project-lite 0.2.7", "tracing-core", ] @@ -3865,9 +3871,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-xid" diff --git a/ansible/templates/nginx.conf b/ansible/templates/nginx.conf index 675925a20..9c9244426 100644 --- a/ansible/templates/nginx.conf +++ b/ansible/templates/nginx.conf @@ -2,6 +2,7 @@ limit_req_zone $binary_remote_addr zone=lemmy_ratelimit:10m rate=1r/s; server { listen 80; + listen [::]:80; server_name {{ domain }}; location /.well-known/acme-challenge/ { root /var/www/certbot; @@ -13,6 +14,7 @@ server { server { listen 443 ssl http2; + listen [::]:443 ssl http2; server_name {{ domain }}; ssl_certificate /etc/letsencrypt/live/{{domain}}/fullchain.pem; diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index 9a921c67a..d71ae70e8 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -45,6 +45,6 @@ sha2 = "0.9.5" async-trait = "0.1.50" captcha = "0.0.8" anyhow = "1.0.41" -thiserror = "1.0.25" +thiserror = "1.0.26" background-jobs = "0.9.0" reqwest = { version = "0.11.4", features = ["json"] } diff --git a/crates/api_crud/Cargo.toml b/crates/api_crud/Cargo.toml index 10b0f63bb..de3360b9a 100644 --- a/crates/api_crud/Cargo.toml +++ b/crates/api_crud/Cargo.toml @@ -39,6 +39,6 @@ uuid = { version = "0.8.2", features = ["serde", "v4"] } sha2 = "0.9.5" async-trait = "0.1.50" anyhow = "1.0.41" -thiserror = "1.0.25" +thiserror = "1.0.26" background-jobs = "0.9.0" reqwest = { version = "0.11.4", features = ["json"] } diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 025e436b1..dc99f3ecf 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -13,7 +13,7 @@ use lemmy_db_schema::source::post::*; use lemmy_db_views::post_view::PostView; use lemmy_utils::{ request::fetch_iframely_and_pictrs_data, - utils::{check_slurs, check_slurs_opt, is_valid_post_title}, + utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title}, ApiError, ConnectionId, LemmyError, @@ -48,7 +48,7 @@ impl PerformCrud for CreatePost { let post_form = PostForm { name: data.name.trim().to_owned(), - url: data_url.map(|u| u.to_owned().into()), + url: data_url.map(|u| clean_url_params(u.to_owned()).into()), body: data.body.to_owned(), community_id: data.community_id, creator_id: local_user_view.person.id, diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index dcf2c95a8..f215da7d0 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -7,7 +7,7 @@ use lemmy_db_schema::{naive_now, source::post::*}; use lemmy_db_views::post_view::PostView; use lemmy_utils::{ request::fetch_iframely_and_pictrs_data, - utils::{check_slurs_opt, is_valid_post_title}, + utils::{check_slurs_opt, clean_url_params, is_valid_post_title}, ApiError, ConnectionId, LemmyError, @@ -59,7 +59,7 @@ impl PerformCrud for EditPost { creator_id: orig_post.creator_id.to_owned(), community_id: orig_post.community_id, name: data.name.to_owned().unwrap_or(orig_post.name), - url: data_url.map(|u| u.to_owned().into()), + url: data_url.map(|u| clean_url_params(u.to_owned()).into()), body: data.body.to_owned(), nsfw: data.nsfw, updated: Some(naive_now()), diff --git a/crates/apub/Cargo.toml b/crates/apub/Cargo.toml index aa0eeadcd..d97edb4a3 100644 --- a/crates/apub/Cargo.toml +++ b/crates/apub/Cargo.toml @@ -46,7 +46,7 @@ uuid = { version = "0.8.2", features = ["serde", "v4"] } sha2 = "0.9.5" async-trait = "0.1.50" anyhow = "1.0.41" -thiserror = "1.0.25" +thiserror = "1.0.26" background-jobs = "0.9.0" reqwest = { version = "0.11.4", features = ["json"] } backtrace = "0.3.60" diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 494ba68d4..225f88018 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -18,7 +18,7 @@ rand = "0.8.4" percent-encoding = "2.1.0" serde = { version = "1.0.126", features = ["derive"] } serde_json = { version = "1.0.64", features = ["preserve_order"] } -thiserror = "1.0.25" +thiserror = "1.0.26" comrak = { version = "0.10.1", default-features = false } lazy_static = "1.4.0" openssl = "0.10.35" diff --git a/crates/utils/src/utils.rs b/crates/utils/src/utils.rs index 7839436b6..ee0289143 100644 --- a/crates/utils/src/utils.rs +++ b/crates/utils/src/utils.rs @@ -4,6 +4,7 @@ use chrono::{DateTime, FixedOffset, NaiveDateTime}; use itertools::Itertools; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use regex::{Regex, RegexBuilder}; +use url::Url; lazy_static! { static ref EMAIL_REGEX: Regex = Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").expect("compile regex"); @@ -25,6 +26,8 @@ lazy_static! { static ref VALID_COMMUNITY_NAME_REGEX: Regex = Regex::new(r"^[a-z0-9_]{3,20}$").expect("compile regex"); static ref VALID_POST_TITLE_REGEX: Regex = Regex::new(r".*\S.*").expect("compile regex"); static ref VALID_MATRIX_ID_REGEX: Regex = Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex"); + // taken from https://en.wikipedia.org/wiki/UTM_parameters + static ref CLEAN_URL_PARAMS_REGEX: Regex = Regex::new(r"^utm_source|utm_medium|utm_campaign|utm_term|utm_content|gclid|gclsrc|dclid|fbclid$").expect("compile regex"); } pub fn naive_from_unix(time: i64) -> NaiveDateTime { @@ -148,3 +151,27 @@ pub fn get_ip(conn_info: &ConnectionInfo) -> IpAddr { .to_string(), ) } + +pub fn clean_url_params(mut url: Url) -> Url { + let new_query = url + .query_pairs() + .filter(|q| !CLEAN_URL_PARAMS_REGEX.is_match(&q.0)) + .map(|q| format!("{}={}", q.0, q.1)) + .join("&"); + url.set_query(Some(&new_query)); + url +} + +#[cfg(test)] +mod tests { + use crate::utils::clean_url_params; + use url::Url; + + #[test] + fn test_clean_url_params() { + let url = Url::parse("https://example.com/path/123?utm_content=buffercf3b2&utm_medium=social&username=randomuser&id=123").unwrap(); + let cleaned = clean_url_params(url); + let expected = Url::parse("https://example.com/path/123?username=randomuser&id=123").unwrap(); + assert_eq!(expected.to_string(), cleaned.to_string()); + } +}