Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion app/src/auth/sign_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ fn provider(forge: &str) -> laravel::Result<Provider> {

/// A path on this site to return to, never another site's URL.
fn safe_return(to: &str) -> Option<String> {
(to.starts_with('/') && !to.starts_with("//") && !to.contains('\\')).then(|| to.to_string())
// Control characters are refused: browsers strip a tab or newline from a Location, so `/\t/evil.com` would
// become `//evil.com`, another site.
(to.starts_with('/')
&& !to.starts_with("//")
&& !to.contains('\\')
&& to.len() <= 4000
&& !to.chars().any(char::is_control))
.then(|| to.to_string())
}

/// `GET /auth/{forge}`: off to the forge.
Expand Down
9 changes: 7 additions & 2 deletions app/tests/sign_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ async fn an_existing_account_is_found_by_a_verified_email(app: Application) -> l
async fn an_unsafe_return_address_is_ignored(app: Application) -> laravel::Result<()> {
let _github = github();
let _social = social::fake().with(Provider::GITHUB, ada());
let start = app.get("/auth/github?return_to=//evil.example/x").await;
app.get("/auth/github/callback").with_cookies_from(&start).await.assert_redirect_to("/");
let long = format!("/{}", "a".repeat(4000));
for to in
["//evil.example/x", "/%09/evil.example", "/%0a/evil.example", "/%0d/evil.example", "/%5C/evil.example", &long]
{
let start = app.get(format!("/auth/github?return_to={to}")).await;
app.get("/auth/github/callback").with_cookies_from(&start).await.assert_redirect_to("/");
}
Ok(())
}

Expand Down
Loading