Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle obfuscated share links #861

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,27 @@ async fn main() {
// Instance info page
app.at("/info").get(|r| instance_info::instance_info(r).boxed());
app.at("/info.:extension").get(|r| instance_info::instance_info(r).boxed());

// Handle obfuscated share links.
// Note that this still forces the server to follow the share link to get to the post, so maybe this wants to be updated with a warning before it follow it
app.at("/r/:sub/s/:id").get(|req: Request<Body>| {
Box::pin(async move {
let sub = req.param("sub").unwrap_or_default();
match req.param("id").as_deref() {

// Share link
Some(id) if (8..12).contains(&id.len()) => match canonical_path(format!("/r/{}/s/{}", sub, id)).await {
Ok(Some(path)) => Ok(redirect(path.split('?').next().unwrap_or_default().to_string())),
Ok(None) => error(req, "Post ID is invalid. It may point to a post on a community that has been banned.").await,
Err(e) => error(req, e).await,
},

// Error message for unknown pages
_ => error(req, "Nothing here".to_string()).await,
}
})
});

app.at("/:id").get(|req: Request<Body>| {
Box::pin(async move {
match req.param("id").as_deref() {
Expand Down