Bug 56288 - rewrite URLs in style attributes
Summary: rewrite URLs in style attributes
Status: REOPENED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_proxy_html (show other bugs)
Version: 2.5-HEAD
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: PatchAvailable
: 56992 (view as bug list)
Depends on: 56284
Blocks:
  Show dependency tree
 
Reported: 2014-03-19 21:22 UTC by Micha Lenk
Modified: 2021-06-22 09:27 UTC (History)
3 users (show)



Attachments
Rewrite URLs in HTML style attributes too (2.41 KB, patch)
2014-03-19 21:22 UTC, Micha Lenk
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Micha Lenk 2014-03-19 21:22:09 UTC
Created attachment 31412 [details]
Rewrite URLs in HTML style attributes too

In HTML you can have <div> tags that have a background image by providing a style attribute. E.g. this can be done by something fancy like this:

<div style="background:url(http://www.example.com/fancy-background.png) right 0px no-repeat; height:325px;">

Currently mod_proxy_html doesn't rewrite the URL in such style attributes.

The attached patch tries to fix that by applying the configured string replacements also on style attributes.

Additionally it tries to make the code a bit more readable by renaming the function dump_content() to apply_urlmap(). This is what it actually does, especially after the call to AP_fwrite() has been moved outside of this function.

Please note that this patch requires the patch from issue #56284 to be applied first. Otherwise the last chunk will not apply.
Comment 1 Nick Kew 2014-06-01 17:15:37 UTC
What are you trying to do that isn't supported by adding style to ProxyHTMLEvents and applying a suitable regexp?
Comment 2 Christophe JAILLET 2014-09-18 14:44:32 UTC
*** Bug 56992 has been marked as a duplicate of this bug. ***
Comment 3 Raffael Luthiger 2014-09-18 14:56:06 UTC
Can you write in the documentation in this case an example of such a regex. As you can see in my bug report I tried it with ProxyHTMLLinks which didn't work. And from reading the documentation it seems to me that it should work as well.

As a side note. I did add "style" to the list of ProxyHTMLEvents. And somehow it still didn't work. Could it be that only one attribute is parsed per element?
Comment 4 Raffael Luthiger 2014-09-18 20:03:04 UTC
One other thing. I did test this on an older machine with apache httpd 2.2.16 with the mod_proxy_html version 3.0.1. And there the style attribute gets parsed. So I would consider this as a bug.
Comment 5 Nick Kew 2017-12-16 20:52:10 UTC
(In reply to Raffael Luthiger from comment #3)
> Can you write in the documentation in this case an example of such a regex.

I'm adding ProxyHTMLLinks and ProxyHTMLEvents usage examples in the docs - thanks for the suggestion.

> As a side note. I did add "style" to the list of ProxyHTMLEvents. And
> somehow it still didn't work. Could it be that only one attribute is parsed
> per element?

"didn't work"?  Have you sorted it yet?  If not, I suggest asking on the users list: the issue is probably a problem with your matching regexp, or with your options/flags.
Comment 6 Micha Lenk 2017-12-17 21:04:45 UTC
Nick, closing a bug with a patch with a clear example of what I expect to get rewritten, but doesn't get rewritten, pretty much looks like you didn't even try. Come on, please give it a try.
Comment 7 Nick Kew 2017-12-22 23:14:14 UTC
I tested it when I closed the bug.

I just retested today with a cut-and-paste of your 
<div style="background:url(http://www.example.com/fancy-background.png) right 0px no-repeat; height:325px;">

Both times, the link got rewritten exactly as I'd expect.  I don't see what else I'm supposed to do here.  So I'll leave this and suggest anyone having similar problems seek help on the mailinglist.
Comment 8 Micha Lenk 2018-05-07 12:45:53 UTC
Hi Nick,

you wrote:
> I just retested today with a cut-and-paste of your 
> <div style="background:url(http://www.example.com/fancy-background.png) right 0px no-repeat; height:325px;">
>
> Both times, the link got rewritten exactly as I'd expect.

Would you mind to provide the exact configuration you used to achieve this rewriting?
Comment 9 Eliseo 2021-06-22 09:27:07 UTC
(In reply to Micha Lenk from comment #8)
> Hi Nick,
> 
> you wrote:
> > I just retested today with a cut-and-paste of your 
> > <div style="background:url(http://www.example.com/fancy-background.png) right 0px no-repeat; height:325px;">
> >
> > Both times, the link got rewritten exactly as I'd expect.
> 
> Would you mind to provide the exact configuration you used to achieve this
> rewriting?

Hi,

The following setup worked for me:

ProxyHTMLLinks  div             style
ProxyHTMLURLMap url\(http: url(https: R