@@ -522,6 +522,16 @@ pub struct CompileOptions {
522522 /// `ircs`, `mailto`, `xmpp`), are safe.
523523 /// All other URLs are dangerous and dropped.
524524 ///
525+ /// When the option `allow_all_protocols_in_img` is enabled,
526+ /// `allow_dangerous_protocol` only applies to links.
527+ ///
528+ /// This is safe because the
529+ /// [HTML specification][whatwg-html-image-processing]
530+ /// does not allow executable code in images.
531+ /// All modern browsers respect this.
532+ ///
533+ /// [whatwg-html-image-processing]: https://html.spec.whatwg.org/multipage/images.html#images-processing-model
534+ ///
525535 /// ## Examples
526536 ///
527537 /// ```
@@ -553,6 +563,55 @@ pub struct CompileOptions {
553563 /// ```
554564 pub allow_dangerous_protocol : bool ,
555565
566+ /// Whether to allow all values in images.
567+ ///
568+ /// The default is `false`,
569+ /// which lets `allow_dangerous_protocol` control protocol safety for
570+ /// both links and images.
571+ ///
572+ /// Pass `true` to allow all values as `src` on images,
573+ /// regardless of `allow_dangerous_protocol`.
574+ /// This is safe because the
575+ /// [HTML specification][whatwg-html-image-processing]
576+ /// does not allow executable code in images.
577+ ///
578+ /// [whatwg-html-image-processing]: https://html.spec.whatwg.org/multipage/images.html#images-processing-model
579+ ///
580+ /// ## Examples
581+ ///
582+ /// ```
583+ /// use markdown::{to_html_with_options, CompileOptions, Options};
584+ /// # fn main() -> Result<(), markdown::message::Message> {
585+ ///
586+ /// // By default, some protocols in image sources are dropped:
587+ /// assert_eq!(
588+ /// to_html_with_options(
589+ /// "",
590+ /// &Options::default()
591+ /// )?,
592+ /// "<p><img src=\"\" alt=\"\" /></p>"
593+ /// );
594+ ///
595+ /// // Turn `allow_any_img_src` on to allow all values as `src` on images.
596+ /// // This is safe because browsers do not execute code in images.
597+ /// assert_eq!(
598+ /// to_html_with_options(
599+ /// ")",
600+ /// &Options {
601+ /// compile: CompileOptions {
602+ /// allow_any_img_src: true,
603+ /// ..CompileOptions::default()
604+ /// },
605+ /// ..Options::default()
606+ /// }
607+ /// )?,
608+ /// "<p><img src=\"javascript:alert(1)\" alt=\"\" /></p>"
609+ /// );
610+ /// # Ok(())
611+ /// # }
612+ /// ```
613+ pub allow_any_img_src : bool ,
614+
556615 // To do: `doc_markdown` is broken.
557616 #[ allow( clippy:: doc_markdown) ]
558617 /// Default line ending to use when compiling to HTML, for line endings not
0 commit comments