Compare commits

..
Author SHA1 Message Date
Ginger 05a49ceb60 chore: Whitelist cognitive_complexity lint 2026-03-18 13:59:48 -04:00
Ginger 728c5828ba feat: Add a panic handler and clean up error page 2026-03-18 13:43:34 -04:00
Ginger 50c94d85a1 fix: Code cleanup 2026-03-18 13:18:53 -04:00
Ginger 0cc188f62c fix: Remove redirect on index 2026-03-18 12:42:55 -04:00
Ginger 6451671f66 fix: Update doc comment 2026-03-18 12:42:55 -04:00
theS1LV3R ca21a885d5 chore: Rename option index_page_allow_indexing to allow_web_indexing 2026-03-18 12:42:55 -04:00
Ginger 4af4110f6d chore: Update news fragment 2026-03-18 12:42:55 -04:00
Ginger 51b450c05c feat: Use a context struct to store global template context 2026-03-18 12:42:55 -04:00
theS1LV3R f9d1f71343 fix: Fix logic error 2026-03-18 12:42:55 -04:00
theS1LV3R 7901e4b996 chore: Add news fragment for !1527 2026-03-18 12:42:55 -04:00
theS1LV3R 7b6bf4b78e feat: Add option for a noindex meta tag on the HTML index page
Adds a new config option `index_page_allow_indexing` which defaults to false.

Fixes: !1527
2026-03-18 12:42:55 -04:00
Ginger 67d5619ccb fix: Fix password reset page appearance in light mode 2026-03-18 12:42:55 -04:00
Ginger bf001f96d6 feat: Restrict reset token command 2026-03-18 12:42:55 -04:00
Ginger ae2b87f03f fix: Fix M_NOT_FOUND for users with no origin set 2026-03-18 12:42:55 -04:00
Ginger 957cd3502f fix: Evil CSS hackery 2026-03-18 12:42:55 -04:00
Ginger a109542eb8 fix: Disable text selection on k10y 2026-03-18 12:42:55 -04:00
Ginger 8c4844b00b fix: Use error page for extractor rejections 2026-03-18 12:42:55 -04:00
Ginger eec7103910 feat: Implement dedicated 404 page for routes under /_continuwuity/ 2026-03-18 12:42:55 -04:00
Ginger 43aa172829 feat: Move index to /_continuwuity/ 2026-03-18 12:42:55 -04:00
Ginger 9b4c483b6d chore: Remove unnecessary database map left over from refactor 2026-03-18 12:42:55 -04:00
Ginger b885e206ce fix: Use server name in index again 2026-03-18 12:42:55 -04:00
Ginger 07a935f625 fix: Add CSRF protection 2026-03-18 12:42:55 -04:00
Ginger d13801e976 fix: Disallow issuing password reset tokens for deactivated users 2026-03-18 12:42:55 -04:00
Ginger 5716c36b47 chore: Change password reset page path 2026-03-18 12:42:55 -04:00
Ginger f11943b956 chore: News fragment 2026-03-18 12:42:55 -04:00
Ginger 8b726a9c94 chore: Cleanup 2026-03-18 12:42:55 -04:00
Ginger ffa3c53847 feat: Implement a webpage for self-service password resets 2026-03-18 12:42:55 -04:00
Ginger da8833fca4 feat: Implement a command for issuing password reset links 2026-03-18 12:42:55 -04:00
Ginger 267feb3c09 feat: Add a new service for handling password resets 2026-03-18 12:42:55 -04:00
Ginger 3d50af0943 refactor: Split web code into multiple files, improve static resource loading 2026-03-18 12:42:55 -04:00
8 changed files with 78 additions and 26 deletions

No files matched your search

+3
View File
@@ -969,3 +969,6 @@ needless_raw_string_hashes = "allow"
# TODO: Enable this lint & fix all instances
collapsible_if = "allow"
# TODO: break these apart
cognitive_complexity = "allow"
+3 -8
View File
@@ -1,10 +1,6 @@
use std::sync::Arc;
use axum::{
Router,
response::{IntoResponse, Redirect},
routing::get,
};
use axum::{Router, response::IntoResponse};
use conduwuit::Error;
use conduwuit_service::{Services, state, state::Guard};
use http::{StatusCode, Uri};
@@ -14,8 +10,7 @@ pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
let router = Router::<state::State>::new();
let (state, guard) = state::create(services.clone());
let router = conduwuit_api::router::build(router, &services.server)
.nest("/_continuwuity/", conduwuit_web::build())
.route("/", get(async || Redirect::permanent("/_continuwuity/")))
.merge(conduwuit_web::build())
.fallback(not_found)
.with_state(state);
@@ -23,5 +18,5 @@ pub(crate) fn build(services: &Arc<Services>) -> (Router, Guard) {
}
async fn not_found(_uri: Uri) -> impl IntoResponse {
Error::Request(ErrorKind::Unrecognized, "Not Found".into(), StatusCode::NOT_FOUND)
Error::Request(ErrorKind::Unrecognized, "not found :(".into(), StatusCode::NOT_FOUND)
}
+35 -13
View File
@@ -1,3 +1,5 @@
use std::any::Any;
use askama::Template;
use axum::{
Router,
@@ -6,7 +8,7 @@ use axum::{
response::{Html, IntoResponse, Response},
};
use conduwuit_service::state;
use tower_http::set_header::SetResponseHeaderLayer;
use tower_http::{catch_panic::CatchPanicLayer, set_header::SetResponseHeaderLayer};
use tower_sec_fetch::SecFetchLayer;
use crate::pages::TemplateContext;
@@ -15,24 +17,29 @@ mod pages;
type State = state::State;
const CATASTROPHIC_FAILURE: &str = "cat-astrophic failure! we couldn't even render the error template. \
please contact the team @ https://continuwuity.org";
#[derive(Debug, thiserror::Error)]
enum WebError {
#[error("Failed to render template: {0}")]
Render(#[from] askama::Error),
#[error("Failed to validate form body: {0}")]
ValidationError(#[from] validator::ValidationErrors),
#[error("{0}")]
QueryRejection(#[from] QueryRejection),
#[error("{0}")]
FormRejection(#[from] FormRejection),
#[error("Bad request: {0}")]
#[error("{0}")]
BadRequest(String),
#[error("This page does not exist.")]
NotFound,
#[error("Internal server error: {0}")]
#[error("Failed to render template: {0}")]
Render(#[from] askama::Error),
#[error("{0}")]
InternalError(#[from] conduwuit_core::Error),
#[error("Request handler panicked! {0}")]
Panic(String),
}
impl IntoResponse for WebError {
@@ -58,8 +65,7 @@ impl IntoResponse for WebError {
error: self,
status,
context: TemplateContext {
// Statically set false to prevent error pages from being indexed and to prevent
// further errors if services.config is having issues.
// Statically set false to prevent error pages from being indexed.
allow_indexing: false,
},
};
@@ -67,7 +73,7 @@ impl IntoResponse for WebError {
if let Ok(body) = template.render() {
(status, Html(body)).into_response()
} else {
(status, "Something went wrong").into_response()
(status, CATASTROPHIC_FAILURE).into_response()
}
}
}
@@ -78,9 +84,25 @@ pub fn build() -> Router<state::State> {
Router::new()
.merge(index::build())
.merge(resources::build())
.merge(password_reset::build())
.fallback(async || WebError::NotFound)
.nest(
"/_continuwuity/",
Router::new()
.merge(resources::build())
.merge(password_reset::build())
.merge(debug::build())
.fallback(async || WebError::NotFound),
)
.layer(CatchPanicLayer::custom(|panic: Box<dyn Any + Send + 'static>| {
let details = if let Some(s) = panic.downcast_ref::<String>() {
s.clone()
} else if let Some(s) = panic.downcast_ref::<&str>() {
(*s).to_owned()
} else {
"(opaque panic payload)".to_owned()
};
WebError::Panic(details).into_response()
}))
.layer(SetResponseHeaderLayer::if_not_present(
header::CONTENT_SECURITY_POLICY,
HeaderValue::from_static("default-src 'self'; img-src 'self' data:;"),
+17
View File
@@ -0,0 +1,17 @@
use std::convert::Infallible;
use axum::{Router, routing::get};
use conduwuit_core::Error;
use crate::WebError;
pub(crate) fn build() -> Router<crate::State> {
Router::new()
.route("/_debug/panic", get(async || -> Infallible { panic!("Guru meditation error") }))
.route(
"/_debug/error",
get(async || -> WebError {
Error::Err(std::borrow::Cow::Borrowed("Guru meditation error")).into()
}),
)
}
+5 -1
View File
@@ -3,7 +3,11 @@ use axum::{Router, extract::State, response::IntoResponse, routing::get};
use crate::{WebError, template};
pub(crate) fn build() -> Router<crate::State> { Router::new().route("/", get(index_handler)) }
pub(crate) fn build() -> Router<crate::State> {
Router::new()
.route("/", get(index_handler))
.route("/_continuwuity/", get(index_handler))
}
async fn index_handler(
State(services): State<crate::State>,
+4
View File
@@ -1,11 +1,14 @@
mod components;
pub(super) mod debug;
pub(super) mod index;
pub(super) mod password_reset;
pub(super) mod resources;
#[derive(Debug)]
pub(crate) struct TemplateContext {
pub allow_indexing: bool,
}
impl From<&crate::State> for TemplateContext {
fn from(state: &crate::State) -> Self {
Self {
@@ -13,6 +16,7 @@ impl From<&crate::State> for TemplateContext {
}
}
}
#[macro_export]
macro_rules! template {
(
+4 -2
View File
@@ -18,6 +18,8 @@ use crate::{
template,
};
const INVALID_TOKEN_ERROR: &str = "Invalid reset token. Your reset link may have expired.";
#[derive(Deserialize)]
struct PasswordResetQuery {
token: String,
@@ -67,7 +69,7 @@ async fn password_reset_form(
reset_form: Form<'static>,
) -> Result<impl IntoResponse, WebError> {
let Some(token) = services.password_reset.check_token(&query.token).await else {
return Err(WebError::BadRequest("Invalid reset token".to_owned()));
return Err(WebError::BadRequest(INVALID_TOKEN_ERROR.to_owned()));
};
let user_card = UserCard::for_local_user(&services, &token.info.user).await;
@@ -96,7 +98,7 @@ async fn post_password_reset(
match form.validate() {
| Ok(()) => {
let Some(token) = services.password_reset.check_token(&query.token).await else {
return Err(WebError::BadRequest("Invalid reset token".to_owned()));
return Err(WebError::BadRequest(INVALID_TOKEN_ERROR.to_owned()));
};
let user_id = token.info.user.clone();
+7 -2
View File
@@ -24,12 +24,17 @@
<h1>
{% if status == StatusCode::NOT_FOUND %}
Not found
{% else if status == StatusCode::INTERNAL_SERVER_ERROR %}
Internal server error
{% else %}
Request error
Bad request
{% endif %}
<small aria-hidden>(︶^︶)</small>
</h1>
{% if status == StatusCode::INTERNAL_SERVER_ERROR %}
<p>Please <a href="https://forgejo.ellis.link/continuwuation/continuwuity/issues/new">submit a bug report</a> 🥺</p>
{% endif %}
<pre><code>{{ error }}</code></pre>
</div>