public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Dominik Csapak <d.csapak@proxmox.com>, pmg-devel@lists.proxmox.com
Subject: Re: [pmg-devel] [PATCH pmg-api v2] fix #3734: scrub 'url' from style tags/attributes
Date: Thu, 25 Nov 2021 18:26:00 +0100	[thread overview]
Message-ID: <24bc3dce-0271-a982-d163-c885e9f92e8a@proxmox.com> (raw)
In-Reply-To: <20211125141441.1383250-1-d.csapak@proxmox.com>

On 25.11.21 15:14, Dominik Csapak wrote:
> if 'view images' for the quarantine is disabled, it is expected that
> *no* images will be loaded. but in addition to img (src/href/etc.)
> also css can load external images via the 'url' directive
> 
> since html scrubber does not parse/iterate over css, we simply remove
> the url+protocol part of those tags/attributes. this technically leaves behind
> invalid css, but the browsers should cope with that.
> (we cannot 'cleanly' remove without much more effort because of quoting)
> 
> also we have to scrub the style tags in 'dump_html' since HTML::Scrubber
> does not have a way to modify the *content* of a tag, only the
> attributes...
>

I found two issues (see inline), I got fully commited followups here, but I did
not push that yet so we can quick check tomorrow if its ok for you and that I
missed nothing else.

> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> changes from v1:
> * replace url with ___ and protocol:// with _ instead of removing
> * move sub out and use the reference
> * always pass $cid_hash and only use it in the function when
>   $view_images is set
> * improve comment to show what 'dump_html' does
> 
> @thomas: a note to our off-list discussion regarding url-encoding the
> protocol: you *could* do it, but the browser does not recognize it as
> a protocol and interprets it as a relative url, so we're safe on
> this regard

thx for checking!

> 
>  src/PMG/HTMLMail.pm | 31 +++++++++++++++++++++++++++----
>  1 file changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/src/PMG/HTMLMail.pm b/src/PMG/HTMLMail.pm
> index b69a596..c5c94bf 100644
> --- a/src/PMG/HTMLMail.pm
> +++ b/src/PMG/HTMLMail.pm
> @@ -15,8 +15,26 @@ use HTML::Scrubber;
>  use PMG::Utils;
>  use PMG::MIMEUtils;
>  
> +# $value is a ref to a string scalar
> +my sub remove_urls {
> +    my ($value) = @_;

$$value can be undef here, so I added a 
return if !defined $$value;

to avoid a ugly warning like:

pmgproxy[164923]: Use of uninitialized value in substitution (s///) at /usr/share/perl5/PMG/HTMLMail.pm line 22.
pmgproxy[164923]: Use of uninitialized value in substitution (s///) at /usr/share/perl5/PMG/HTMLMail.pm line 25.

every time one loads a mail where this happens.

> -- 8< snip 8< --

> @@ -137,7 +159,7 @@ sub getscrubber {
>  	    span => 1,
>  	    src => $viewimages ? qr{^(?!(?:java)?script)}i : 0,
>  	    start => 1,
> -	    style => 1,
> +	    style => $viewimages ? 1 : \remove_urls_from_attr,

this actually does not works as expected, to get the callback functionality we need
to set it at the "rules" one, not here at the "default" one, which really just is the
boolean default for that attribute type, and setting it to an code ref-makes may call
it once but due to returning undef it just plainly disables the tag, which is way more
scrubbing than we want to achieve.




  reply	other threads:[~2021-11-25 17:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-25 14:14 Dominik Csapak
2021-11-25 17:26 ` Thomas Lamprecht [this message]
2021-11-26  7:28 ` Thomas Lamprecht
2021-11-26  7:51   ` Dominik Csapak
2021-11-26  9:07 ` [pmg-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=24bc3dce-0271-a982-d163-c885e9f92e8a@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=d.csapak@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal