xss_safety.rs 525 B

123456789101112131415161718192021222324
  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, || String::from("<script>alert(123)</script>"));
  10. cx.render(rsx! {
  11. div {
  12. h3 { "{contents}" }
  13. input {
  14. value: "{contents}",
  15. r#type: "text",
  16. oninput: move |e| contents.set(e.value.clone()),
  17. }
  18. }
  19. })
  20. }