Crates.io | axum_js_advice |
lib.rs | axum_js_advice |
version | |
source | src |
created_at | 2025-01-16 01:51:31.028102+00 |
updated_at | 2025-01-16 14:09:47.924818+00 |
description | This project allows you to includes a custom middleware that injects a JavaScript alert in your axum application, advising users to disable JavaScript for enhanced security |
homepage | |
repository | https://gitlab.torproject.org/mateolafalce/axum_js_advice |
max_upload_size | |
id | 1518849 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
This project allows you to includes a custom middleware that injects a JavaScript alert in your axum application, advising users to disable JavaScript for enhanced security.
<script>
tag to responses, displaying a warning pop-up if JavaScript is enabled.axum
and tokio
.The middleware intercepts responses and appends a JavaScript alert to the body. The alert advises users to disable JavaScript for their safety.
<script>
alert("Warning!\nYou have JavaScript enabled, you are putting yourself at risk!\nPlease disable it immediately!");
</script>
cargo add axum_js_advice
Then, add axum_js_advice() in your middleware layer, for example:
use axum::{middleware, Router};
use axum_js_advice::js_advice;
#[tokio::main]
async fn main() {
let app = Router::new()
.route(
"/",
axum::routing::get(|| async move { axum::response::Html("Hello from `POST /`") }),
)
//.layer(middleware::from_fn(OTHER_MIDDLEWARE_RULE))
.layer(middleware::from_fn(js_advice));
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
println!("listening on {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();
}
cargo run --example middleware
When visiting http://127.0.0.1:3000/
, the response will include:
<script>
alert("Warning!\nYou have JavaScript enabled, you are putting yourself at risk!\nPlease disable it immediately!");
</script>
Hello from `POST /`
If you have JavaScript enabled, a reminder will pop up asking you to disable it; otherwise, you can browse freely.
This project is licensed under the GPL License. See the LICENSE file for details.