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