xss_safety.rs 591 B

123456789101112131415161718192021222324252627
  1. //! XSS Safety
  2. //!
  3. //! This example proves that Dioxus is safe from XSS attacks.
  4. use dioxus::prelude::*;
  5. fn main() {
  6. dioxus::desktop::launch(app);
  7. }
  8. fn app(cx: Scope) -> Element {
  9. let contents = use_state(&cx, || {
  10. String::from("<script>alert(\"hello world\")</script>")
  11. });
  12. cx.render(rsx! {
  13. div {
  14. h1 {"Dioxus is XSS-Safe"}
  15. h3 { "{contents}" }
  16. input {
  17. value: "{contents}",
  18. r#type: "text",
  19. oninput: move |e| contents.set(e.value.clone()),
  20. }
  21. }
  22. })
  23. }