Edgewall Software
Modify

Ticket #7768 (closed defect: fixed)

Opened 3 years ago

Last modified 17 months ago

add_script & add_stylesheet don't support external scripts

Reported by: martin@… Owned by: rblank
Priority: high Milestone: 0.13
Component: web frontend Version:
Severity: normal Keywords: add_script
Cc: ryano@…
Release Notes:

API only

API Changes:

trac.web.chrome: add_script() and add_stylesheet() now also accept absolute URLs [10027]

Description

Not sure if this was indented as a security feature, but:

The add_script from trac.web.chrome doesn't support external script URLs, i.e. one which start with 'http://'. At the moment the full URL is appended to the chrome path resulting in a dysfunctional script tag.

The same should be true for add_stylesheet.

If this is indented as a security feature, then be warned that it is easily overcome by just coping and changing the add_script source code, like I did in my GoogleMapMacro, where I have to load the external Google Map API JavaScript file.

Attachments

allow_absolute_urls_for_add_script_add_stylesheet.patch (1.1 KB) - added by mark.m.mcmahon@… 18 months ago.
Adds a check for the filename starting with http

Download all attachments as: .zip

Change History

comment:1 Changed 3 years ago by cboos

  • Component changed from general to web frontend
  • Keywords add_script added
  • Milestone set to 0.13

Well, it's certainly not a "security feature", as you can always to whatever you want in plugins ;-)

comment:3 Changed 18 months ago by mark.m.mcmahon@…

Not really sure if this patch is correct or not - but adding it here for feedback/improvements.

Changed 18 months ago by mark.m.mcmahon@…

Adds a check for the filename starting with http

comment:4 Changed 18 months ago by rblank

  • Milestone changed from next-major-0.1X to 0.13
  • Owner set to rblank

Looks good.

comment:5 Changed 18 months ago by Ryan J Ollos <ryano@…>

  • Cc ryano@… added

comment:6 Changed 18 months ago by rblank

  • Priority changed from normal to high

comment:7 Changed 18 months ago by rblank

  • Resolution set to fixed
  • Status changed from new to closed

... well, not quite good :) Your patch doesn't define href in the "absolute URL" case.

I have applied an improved version in [10027], together with updated unit tests that check the correct behavior.

Mark, I hope you don't mind if I give you some advice for you next patches:

  • Always run the unit tests and functional tests before posting your patch. This should catch most of the more obvious errors.
  • If possible, add one or more unit tests (or modify existing tests) to check for the correctness of your changes.
  • Always create your patches from the project root, so that full paths are recorded. This makes it simpler for the reviewer to apply them.

But most importantly: keep up the good work!

comment:8 Changed 17 months ago by cboos

  • API Changes modified (diff)
  • Release Notes modified (diff)
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from rblank. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.