⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 249200 in webkit


Ignore:
Timestamp:
Aug 28, 2019, 8:45:20 AM (7 years ago)
Author:
Jonathan Bedard
Message:

results.webkit.org: Sanitize all commit arguments on upload
https://bugs.webkit.org/show_bug.cgi?id=201189
<rdar://problem/54564837>

Reviewed by Aakash Jain.

  • resultsdbpy/resultsdbpy/controller/commit.py:

(Commit.init): Only allow commits to be constructed with valid values.

  • resultsdbpy/resultsdbpy/controller/commit_controller.py:

(CommitController.register): Strip potential API key.

  • resultsdbpy/resultsdbpy/controller/commit_unittest.py:

(CommitUnittest.test_invalid): Test that commits which contain html inside the
repository_id, branch or commit id are rejected.

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r249192 r249200  
     12019-08-28  Jonathan Bedard  <jbedard@apple.com>
     2
     3        results.webkit.org: Sanitize all commit arguments on upload
     4        https://bugs.webkit.org/show_bug.cgi?id=201189
     5        <rdar://problem/54564837>
     6
     7        Reviewed by Aakash Jain.
     8
     9        * resultsdbpy/resultsdbpy/controller/commit.py:
     10        (Commit.__init__): Only allow commits to be constructed with valid values.
     11        * resultsdbpy/resultsdbpy/controller/commit_controller.py:
     12        (CommitController.register): Strip potential API key.
     13        * resultsdbpy/resultsdbpy/controller/commit_unittest.py:
     14        (CommitUnittest.test_invalid): Test that commits which contain html inside the
     15        repository_id, branch or commit id are rejected.
     16
    1172019-08-02  Claudio Saavedra  <csaavedra@igalia.com>
    218
  • trunk/Tools/resultsdbpy/resultsdbpy/controller/commit.py

    r247628 r249200  
    2323import calendar
    2424import json
     25import re
    2526
    2627from datetime import datetime
     
    3031class Commit(object):
    3132    TIMESTAMP_TO_UUID_MULTIPLIER = 100
     33    MAX_KEY_LENGTH = 128
    3234
    3335    @classmethod
     
    5052
    5153        self.repository_id = str(repository_id)
     54        if not re.match(r'^[a-zA-Z?]+$', self.repository_id) or len(self.repository_id) > self.MAX_KEY_LENGTH:
     55            raise ValueError(f"'{self.repository_id}' is an invalid repository id")
     56
    5257        self.branch = str(branch)
     58        if not re.match(r'^[a-zA-Z0-9-.?/]+$', self.branch) or len(self.branch) > self.MAX_KEY_LENGTH:
     59            raise ValueError(f"'{self.branch}' is an invalid branch name")
    5360
    5461        # An id is either a git commit or SVN revision.
    5562        self.id = str(id)
     63        if not re.match(r'^[a-fA-F0-9?]+$', self.id) or len(self.id) > 40:
     64            raise ValueError(f"'{self.id}' is an invalid commit id")
    5665
    5766        if isinstance(timestamp, datetime):
  • trunk/Tools/resultsdbpy/resultsdbpy/controller/commit_controller.py

    r247628 r249200  
    268268            try:
    269269                commit = request.form or json.loads(request.get_data())
     270                if 'api_key' in commit:
     271                    del commit['api_key']
    270272            except ValueError:
    271273                abort(400, description='Expected uploaded data to be json')
  • trunk/Tools/resultsdbpy/resultsdbpy/controller/commit_unittest.py

    r247628 r249200  
    101101
    102102    def test_invalid(self):
    103         with self.assertRaises(ValueError):
     103        with self.assertRaises(ValueError) as error:
    104104            Commit(
    105105                repository_id='safari', branch='master',
     
    107107                timestamp=None,
    108108            )
     109        self.assertEqual(str(error.exception), 'timestamp is not defined for commit')
     110
     111        with self.assertRaises(ValueError) as error:
     112            Commit(
     113                repository_id='invalid-repo', branch='master',
     114                id='7be4084258a452e8fe22f36287c5b321e9c8249b',
     115                timestamp=1537550685,
     116            )
     117        self.assertEqual(str(error.exception), "'invalid-repo' is an invalid repository id")
     118
     119        with self.assertRaises(ValueError) as error:
     120            Commit(
     121                repository_id='i' * 129, branch='master',
     122                id='7be4084258a452e8fe22f36287c5b321e9c8249b',
     123                timestamp=1537550685,
     124            )
     125        self.assertEqual(str(error.exception), f"'{'i' * 129}' is an invalid repository id")
     126
     127        with self.assertRaises(ValueError) as error:
     128            Commit(
     129                repository_id='safari', branch='<html>invalid-branch</html>',
     130                id='7be4084258a452e8fe22f36287c5b321e9c8249b',
     131                timestamp=1537550685,
     132            )
     133        self.assertEqual(str(error.exception), "'<html>invalid-branch</html>' is an invalid branch name")
     134
     135        with self.assertRaises(ValueError) as error:
     136            Commit(
     137                repository_id='safari', branch='i' * 129,
     138                id='7be4084258a452e8fe22f36287c5b321e9c8249b',
     139                timestamp=1537550685,
     140            )
     141        self.assertEqual(str(error.exception), f"'{'i' * 129}' is an invalid branch name")
     142
     143        with self.assertRaises(ValueError) as error:
     144            Commit(
     145                repository_id='safari', branch='master',
     146                id='<html>1234</html>',
     147                timestamp=1537550685,
     148            )
     149        self.assertEqual(str(error.exception), "'<html>1234</html>' is an invalid commit id")
     150
     151        with self.assertRaises(ValueError) as error:
     152            Commit(
     153                repository_id='safari', branch='master',
     154                id='0' * 41,
     155                timestamp=1537550685,
     156            )
     157        self.assertEqual(str(error.exception), f"'{'0' * 41}' is an invalid commit id")
Note: See TracChangeset for help on using the changeset viewer.