2022-01-03 07:35:38 +08:00
|
|
|
//! XSS Safety
|
|
|
|
//!
|
|
|
|
//! This example proves that Dioxus is safe from XSS attacks.
|
|
|
|
|
2021-12-30 16:14:47 +08:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2022-07-10 03:15:20 +08:00
|
|
|
dioxus_desktop::launch(app);
|
2021-12-30 16:14:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
2022-12-08 05:11:40 +08:00
|
|
|
let contents = use_state(cx, || {
|
2022-01-03 13:42:17 +08:00
|
|
|
String::from("<script>alert(\"hello world\")</script>")
|
|
|
|
});
|
2021-12-30 16:14:47 +08:00
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
2022-01-03 13:42:17 +08:00
|
|
|
h1 {"Dioxus is XSS-Safe"}
|
2022-01-03 07:35:38 +08:00
|
|
|
h3 { "{contents}" }
|
2021-12-30 16:14:47 +08:00
|
|
|
input {
|
|
|
|
value: "{contents}",
|
2022-01-03 07:35:38 +08:00
|
|
|
r#type: "text",
|
2022-03-01 15:50:03 +08:00
|
|
|
oninput: move |e| contents.set(e.value.clone()),
|
2021-12-30 16:14:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|