Markdown and XSS

前端 未结 5 1708
萌比男神i
萌比男神i 2020-12-31 10:20

Ok, so I have been reading about markdown here on SO and elsewhere and the steps between user-input and the db are usually given as

  1. convert markdown to html
5条回答
  •  忘掉有多难
    2020-12-31 10:49

    1. insert into database
    2. convert markdown to html
    3. sanitize html (w/whitelist)

    perl

    use Text::Markdown ();
    use HTML::StripScripts::Parser ();
    
    my $hss = HTML::StripScripts::Parser->new(
       {
           Context         => 'Document',
           AllowSrc        => 0,
           AllowHref       => 1,
           AllowRelURL     => 1,
           AllowMailto     => 1,
           EscapeFiltered  => 1,
       },
       strict_comment => 1,
       strict_names   => 1,
    );
    
    $hss->filter_html(Text::Markdown::markdown(shift))
    

提交回复
热议问题