Merge lp:~sinzui/launchpad/product-release-file-api into lp:launchpad/db-devel

Proposed by Curtis Hovey on 2010-03-01
Status: Merged
Approved by: Tim Penhey on 2010-03-01
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~sinzui/launchpad/product-release-file-api
Merge into: lp:launchpad/db-devel
Diff against target: 33 lines (+11/-1)
2 files modified
lib/canonical/launchpad/doc/tales.txt (+10/-0)
lib/canonical/launchpad/webapp/tales.py (+1/-1)
To merge this branch: bzr merge lp:~sinzui/launchpad/product-release-file-api
Reviewer Review Type Date Requested Status
Tim Penhey (community) release-critical Approve on 2010-03-01
Brad Crittenden (community) code 2010-03-01 Approve on 2010-03-01
Review via email: mp+20398@code.launchpad.net
To post a comment you must log in.
Curtis Hovey (sinzui) wrote :

This is my branch to secure <ProductReleaseFile>/fmt:link.

    lp:~sinzui/launchpad/product-release-file-api
    Diff size: 34
    Launchpad bug: https://bugs.launchpad.net/bugs/529370
    Test command: ./bin/test -vv \
        -t doc/tales.txt
    Pre-implementation: no one.
    Target release: 10.02

Secure <ProductReleaseFile>/fmt:link
------------------------------------

ProductReleaseFileFormatterAPI.link injects ProductReleaseFile.description
into a title attribute without any escaping.

Rules
-----

    * Update the tales link formatter for ProductReleaseFile to escape the
      the description.

QA
--

    * Upload a file and set the description to:
      ><script>window.alert('xss attack')</script>
    * Verify when viewing the file on the release or download page that
      you do not get a popup, instead you see the text when you hover over
      the file link.

Lint
----

Linting changed files:
  lib/canonical/launchpad/doc/tales.txt
  lib/canonical/launchpad/webapp/tales.py

Test
----

    * lib/canonical/launchpad/doc/tales.txt
      Added a test to verify that the description is escaped in the
      link's title attribute.

Implementation
--------------

    * lib/canonical/launchpad/webapp/tales.py
      Used cgi.escape() to create a safe description that can be placed
      in the title of a link to download the file.

Brad Crittenden (bac) :
review: Approve (code)
Tim Penhey (thumper) :
review: Approve (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/doc/tales.txt'
2--- lib/canonical/launchpad/doc/tales.txt 2010-02-23 15:10:46 +0000
3+++ lib/canonical/launchpad/doc/tales.txt 2010-03-01 21:21:25 +0000
4@@ -646,6 +646,16 @@
5 >>> print test_tales("release_file/fmt:url", release_file=release_file)
6 http://launchpad.dev/.../+download/test.txt
7
8+HTML in the file description is escaped in the fmt:link.
9+
10+ >>> release_file.description = (
11+ ... '><script>XSS failed</script>')
12+ >>> print test_tales("release_file/fmt:link", release_file=release_file)
13+ <img ...
14+ <a title="&gt;&lt;script&gt;XSS failed&lt;/script&gt; (4 bytes)"
15+ href="http://launchpad.dev/.../+download/test.txt">test.txt</a> ...
16+
17+
18
19 Product series
20 ..............
21
22=== modified file 'lib/canonical/launchpad/webapp/tales.py'
23--- lib/canonical/launchpad/webapp/tales.py 2010-02-17 14:46:57 +0000
24+++ lib/canonical/launchpad/webapp/tales.py 2010-03-01 21:21:25 +0000
25@@ -1348,7 +1348,7 @@
26 file_size = NumberFormatterAPI(
27 file_.libraryfile.content.filesize).bytes()
28 if file_.description is not None:
29- description = file_.description
30+ description = cgi.escape(file_.description)
31 else:
32 description = file_.libraryfile.filename
33 link_title = "%s (%s)" % (description, file_size)

Subscribers

People subscribed via source and target branches

to status/vote changes: