|
|
Mads Kiilerich
|
19d93bd709bf
|
6 years ago
|
|
html: put 'use strict' on separate lines
use.py: import re import sys for fn in sys.argv[1:]: with open(fn) as f: s = f.read() s = re.sub(r'''(<script>)('use strict';)\n( *)''', r'''\1\n\3\2\n\3''', s) with open(fn, 'w') as f: f.write(s)
python use.py $(hg loc 'kallithea/templates/**.html')
|
|
|
Mads Kiilerich
|
d6efaa91e967
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
f4e158ed49b1
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
fb9550946c26
|
6 years ago
|
|
js: use strict ... and fix the problems it points out
"use strict" gives stricter checks, both statically and at runtime. The strictness tightens up the code and prevents some kinds of problems.
The <script> tag addition might not be pretty, but has consistently been added with:
sed -i 's,<script>$,&'"'"'use strict'"'"';,g' `hg loc '*.html'`
|
|
|
Mads Kiilerich
|
1f3e993156e4
|
6 years ago
|
|
|
|
|
Mads Kiilerich
|
ee3343f3658f
|
8 years ago
|
|
style: drop form-horizontal - our style is much closer to plain Bootstrap forms
form-horizontal is made for grid markup. It give form-groups a negative margin to break out of the grid ... but the way we use it for settings, we have to do weird things to undo that. The default styling for forms is much closer to what we want. It looks ok without our custom styling and is easier to style to our style.
If we want grid markup with form-horizontal, it would be correct to re-introduce both at once.
|
|
|
Mads Kiilerich
|
88ce09daea37
|
8 years ago
|
|
|
|
|
Mads Kiilerich
|
8dd57541a2f7
|
8 years ago
|
|
pullrequests: fix graph re-drawing on 'expand' of changeset description while creating PR
Expanding would fail with TypeError: r.render is not a function
To fix this, do all the graph drawing in compare_cs.html .
|
|
|
Søren Løvborg
|
62ac1470b748
|
9 years ago
|
|
pullrequests: rename "as_form" to something more descriptive
This parameter is (only) used for showing the PR contents preview on the "New Pull Request" page.
|
|
|
Søren Løvborg
|
33b71a130b16
|
9 years ago
|
|
templates: properly escape inline JavaScript values
TLDR: Kallithea has issues with escaping values for use in inline JS. Despite judicious poking of the code, no actual security vulnerabilities have been found, just lots of corner-case bugs. This patch fixes those, and hardens the code against actual security issues.
The long version:
To embed a Python value (typically a 'unicode' plain-text value) in a larger file, it must be escaped in a context specific manner. Example:
>>> s = u'<script>alert("It\'s a trap!");</script>'
1) Escaped for insertion into HTML element context
>>> print cgi.escape(s) <script>alert("It's a trap!");</script>
2) Escaped for insertion into HTML element or attribute context
>>> print h.escape(s) <script>alert("It's a trap!");</script>
This is the default Mako escaping, as usually used by Kallithea.
3) Encoded as JSON
>>> print json.dumps(s) "<script>alert(\"It's a trap!\");</script>"
4) Escaped for insertion into a JavaScript file
>>> print '(' + json.dumps(s) + ')' ("<script>alert(\"It's a trap!\");</script>")
The parentheses are not actually required for strings, but may be needed to avoid syntax errors if the value is a number or dict (object).
5) Escaped for insertion into a HTML inline <script> element
>>> print h.js(s) ("\x3cscript\x3ealert(\"It's a trap!\");\x3c/script\x3e")
Here, we need to combine JS and HTML escaping, further complicated by the fact that "<script>" tag contents can either be parsed in XHTML mode (in which case '<', '>' and '&' must additionally be XML escaped) or HTML mode (in which case '</script>' must be escaped, but not using HTML escaping, which is not available in HTML "<script>" tags). Therefore, the XML special characters (which can only occur in string literals) are escaped using JavaScript string literal escape sequences.
(This, incidentally, is why modern web security best practices ban all use of inline JavaScript...)
Unsurprisingly, Kallithea does not do (5) correctly. In most cases, Kallithea might slap a pair of single quotes around the HTML escaped Python value. A typical benign example:
$('#child_link').html('${_('No revisions')}');
This works in English, but if a localized version of the string contains an apostrophe, the result will be broken JavaScript. In the more severe cases, where the text is user controllable, it leaves the door open to injections. In this example, the script inserts the string as HTML, so Mako's implicit HTML escaping makes sense; but in many other cases, HTML escaping is actually an error, because the value is not used by the script in an HTML context.
The good news is that the HTML escaping thwarts attempts at XSS, since it's impossible to inject syntactically valid JavaScript of any useful complexity. It does allow JavaScript errors and gibberish to appear on the page, though.
In these cases, the escaping has been fixed to use either the new 'h.js' helper, which does JavaScript escaping (but not HTML escaping), OR the new 'h.jshtml' helper (which does both), in those cases where it was unclear if the value might be used (by the script) in an HTML context. Some of these can probably be "relaxed" from h.jshtml to h.js later, but for now, using h.jshtml fixes escaping and doesn't introduce new errors.
In a few places, Kallithea JSON encodes values in the controller, then inserts the JSON (without any further escaping) into <script> tags. This is also wrong, and carries actual risk of XSS vulnerabilities. However, in all cases, security vulnerabilities were narrowly avoided due to other filtering in Kallithea. (E.g. many special characters are banned from appearing in usernames.) In these cases, the escaping has been fixed and moved to the template, making it immediately visible that proper escaping has been performed.
Mini-FAQ (frequently anticipated questions):
Q: Why do everything in one big, hard to review patch? Q: Why add escaping in specific case FOO, it doesn't seem needed?
Because the goal here is to have "escape everywhere" as the default policy, rather than identifying individual bugs and fixing them one by one by adding escaping where needed. As such, this patch surely introduces a lot of needless escaping. This is no different from how Mako/Pylons HTML escape everything by default, even when not needed: it's errs on the side of needless work, to prevent erring on the side of skipping required (and security critical) work.
As for reviewability, the most important thing to notice is not where escaping has been introduced, but any places where it might have been missed (or where h.jshtml is needed, but h.js is used).
Q: The added escaping is kinda verbose/ugly.
That is not a question, but yes, I agree. Hopefully it'll encourage us to move away from inline JavaScript altogether. That's a significantly larger job, though; with luck this patch will keep us safe and secure until such a time as we can implement the real fix.
Q: Why not use Mako filter syntax ("${val|h.js}")?
Because of long-standing Mako bug #140, preventing use of 'h' in filters.
Q: Why not work around bug #140, or even use straight "${val|js}"?
Because Mako still applies the default h.escape filter before the explicitly specified filters.
Q: Where do we go from here?
Longer term, we should stop doing variable expansions in script blocks, and instead pass data to JS via e.g. data attributes, or asynchronously using AJAX calls. Once we've done that, we can remove inline JavaScript altogether in favor of separate script files, and set a strict Content Security Policy explicitly blocking inline scripting, and thus also the most common kind of cross-site scripting attack.
|
|
|
Mads Kiilerich
|
03746b8cd5c9
|
9 years ago
|
|
style: use more Bootstrap pull-left and pull-right
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
1f02a239c23c
|
9 years ago
|
|
style: use panel, panel-heading, panel-title, panel-body and settings
This imply lots of tweaking of header handling and panel spacing.
Not converted yet: codeblock code-header code-body.
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
8656c0073e17
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
785a9770e8e0
|
9 years ago
|
|
templates: textarea doesn't have a size attribute - drop it!
We could use the rows attribute ... but so far it has worked without ...
|
|
|
Mads Kiilerich
|
a79e651306e2
|
9 years ago
|
|
style: add missing 'form-control' markup
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
cf3cc1fa4222
|
9 years ago
|
|
style: drop 'textarea' class inside 'form-group'
Temporarily, just apply styling to div inside form-group. Also, 'radios' is gone.
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
dd42c2ad28d7
|
9 years ago
|
|
style: drop 'input' class inside 'form-group'
As long as we use the old styling, just apply styling to div inside form-group.
Based on work by Dominik Ruf.
|
|
|
domruf
|
67e53a272e1a
|
9 years ago
|
|
templates: use Bootstrap compatible 'form-control' name instead of 'medium' & co
In Bootstrap, form controls tend to be 100%.
|
|
|
Mads Kiilerich
|
33ca6d0f7058
|
9 years ago
|
|
style: introduce "clearfix" class where the Bootstrap migration will need it
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
6f4f39b21302
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
68d3315c48d4
|
9 years ago
|
|
|
|
|
domruf
|
48a96c4059df
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
d1923cd0521c
|
9 years ago
|
|
style: refactor form label styling to prepare for Bootstrap and get rid of wrapping with 'label' class
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
4304595d246c
|
9 years ago
|
|
style: in preparation for Bootstrap, refactor to use Bootstrap compatible form class names
Based on work by Dominik Ruf.
Mostly:
sed -i \ -e 's,<table>,<table class="table">,g' \ -e 's,<div class="fields">,<div class="form-horizontal">,g' \ -e 's,<div class="field">,<div class="form-group">,g' \ -e 's,<label for="\([^"]*\)">,<label class="control-label" for="\1">,g' \ `hg mani`
cat kallithea/public/css/style.css | \ sed -e '/\.fields\>/{p;s/\.fields/.form-horizontal/g}' | \ sed -e '/\.fields\>/s/ {$/,/g' | \ sed -e '/\.field\>/{p;s/\.field\>/.form-group/g}' | \ sed -e '/\.field\>/s/ {$/,/g' | \ sed -e '/\.fields\>.*\.form-group\>/d' | \ sed -e '/\.form-horizontal\>.*\.field\>/d ' | \ cat - > kallithea/public/css/style.css.tmp mv kallithea/public/css/style.css.tmp kallithea/public/css/style.css
|
|
|
domruf
|
ee3fb2dfbcc0
|
9 years ago
|
|
style: in preparation for bootstrap, replace kallithea title class with bootstrap compatible panel-heading
This is a subset of a bigger changeset. The subset was extracted by Mads Kiilerich, mostly by:
sed -i 's,<div class="title\>,<div class="panel-heading,g' `hg mani` sed -i 's,\<div\.title\>,div.panel-heading,g' kallithea/public/css/style.css
|
|
|
domruf
|
80a15e10857a
|
9 years ago
|
|
style: in preparation for bootstrap, replace kallithea box with bootstrap compatible panel
This is a subset of a bigger changeset. The subset was extracted by Mads Kiilerich, mostly by:
sed -i \ -e 's,<div\(.*\) class="box",<div\1 class="panel panel-primary",g' \ `hg mani`
|
|
|
domruf
|
b7654d1675da
|
9 years ago
|
|
style: in preparation for bootstrap, use bootstrap compatible button class names
Give all buttons a styling (default, success, danger, warning) and rename the sizes to sm and xs.
This is a subset of a bigger changeset. The subset was extracted by Mads Kiilerich, mostly by:
sed -i \ -e 's,btn btn-small,btn btn-default btn-sm,g' \ -e 's,btn btn-mini,btn btn-default btn-xs,g' \ -e 's,btn-default btn-\(xs\|sm\) btn-\(success\|danger\|warning\),btn-\2 btn-\1,g' \ -e 's,class_="btn",class_="btn btn-default",g' \ `hg mani`
|
|
|
Mads Kiilerich
|
190cb30841de
|
9 years ago
|
|
branches: fix performance of branch selectors with many branches - only show the first 200 results
The way we use select2, it will cause browser performance problems when a select list contains thousands of entries. The primary bottleneck is the DOM creation, secondarily for the query to filter through the entries and decide what to show. We thus primarily have to limit how many entries we put in the drop-down, secondarily limit the iteration over data.
One tricky case is where the user specifies a short but full branch name (like 'trunk') but many other branches contains the same string (not necessarily at the beginning, like 'for-trunk-next-week') which come before the perfect match in the branch list. It is thus not a solution to just stop searching when a fixed amount of matches have been found.
Instead, we limit the amount of ordinary query matches, but always show all prefix matches. We thus always have to iterate through all entries, but we start using the (presumably) cheaper prefix search when the limit has been reached.
There is no filtering initially when there is no query term, so that case has to be handled specially.
Upstream select2 is now at 4.x. Upgrading is not trivial, and getting this fixed properly upstream is not a short term solution. Instead, we customize our copy. The benefit from this patch is bigger than the overhead of "maintaining" it locally.
|
|
|
Mads Kiilerich
|
5dfe741d2b0a
|
9 years ago
|
|
js: workaround to avoid <option> tags inside <script>
The naive formencode html parser would sometimes (Python 2.6?) fail with AssertionError: <option> outside of <select>
|
|
|
Mads Kiilerich
|
f0cdd5efc867
|
9 years ago
|
|
pull-requests: fix missing YUD reference in PR creation Missed this one in 81a1eb6cd56e ...
|
|
|
timeless@gmail.com
|
5ac263d4ae6c
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
3f017db297c4
|
10 years ago
|
|
|
|
|
Søren Løvborg
|
42ce8e54bae5
|
10 years ago
|
|
pullrequests: remove reviewer list during PR creation
There is not much use for it before the actual diff is shown ... and removing it also removes a bit of duplicated code that otherwise should be maintained in two places.
|
|
|
Mads Kiilerich
|
2fa786ba2b2a
|
10 years ago
|
|
js: refactor AutoComplete functions to pass jQuery results around until DOM elements are passed to YUI
A small step forward that enables other refactorings.
|
|
|
Thomas De Schampheleire
|
96ed562709f9
|
10 years ago
|
|
autocomplete: remove dead code
The three blocks of autocomplete code are clearly copy/pasted from one another, with dead code remaining due to group-autocomplete not being relevant for some cases.
|
|
|
Daniel Hobley
|
4f4d2e899a02
|
11 years ago
|
|
select2: move "exact prefix matches" to the top of the search
Further improvements to this could be to sort by the position of your filter in the results so searching for foo means that release/foo comes before a/branch/of/doom//foo .
|
|
|
Mads Kiilerich
|
c5f49ffbd72b
|
12 years ago
|
|
|
|
|
Mads Kiilerich
|
37354e1ab283
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
ec39e73be935
|
11 years ago
|
|
|
|
|
Sean Farley
|
882f300d652e
|
11 years ago
|
|
icons: fix typo of icon-remove to icon-minus and remove style color
This patch helps unify some of the visual style at a very basic level. We will punt on doing a more in-depth edit of the visual style until later.
|
|
|
Sean Farley
|
315e8a847e2e
|
11 years ago
|
|
gravatar: use font awesome icons
This changes gravatar_url to return an empty string (meaning use an icon) instead of returning a default image. Since this was a structural change, the changeset is fairly large.
|
|
|
Mads Kiilerich
|
dba66b0768f4
|
11 years ago
|
|
|
|
|
Takumi IINO
|
94a7abdac8f6
|
11 years ago
|
|
|
|
|
Takumi IINO
|
4a57462b5101
|
11 years ago
|
|
|
|
|
Sean Farley
|
b5795554c2ca
|
11 years ago
|
|
icon-remove: use new icon-minus-circled instead
To remove the css that set the background of the submit input (h.submit), the element needed to be changed to <button>.
|
|
|
Mads Kiilerich
|
cb360bf40863
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
dbd2f2891585
|
11 years ago
|
|
pull requests: abort pending ajax requests before starting new one
Quick navigation and different load times could cause an old result to overwrite a new one.
|
|
|
Mads Kiilerich
|
dcf7fe7a8e9a
|
11 years ago
|
|
|
|
|
Na'Tosha Bard
|
dacdea9fda2a
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
b3f12c354e87
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
155f281be5f8
|
11 years ago
|
|
javascript: use jQuery for ypjax and rename to asynchtml
The container id is replaced with a $target jQuery array.
|
|
|
Mads Kiilerich
|
72747179701a
|
11 years ago
|
|
javascript: ypjax cleanup
Set 'Loading ...' while waiting for response.
|
|
|
Mads Kiilerich
|
6cb077e99873
|
11 years ago
|
|
diff: rename template values for org and other for compare and PR
sed -i -e 's,\<\(c\.\(default_\)\?\)org_,\1a_,g' -e 's,\<\(c\.\(default_\)\?\)other_,\1cs_,g' kallithea/controllers/compare.py kallithea/templates/compare/compare_cs.html kallithea/templates/compare/compare_diff.html sed -i -e 's,\<\(c\.\(default_\)\?\)org_,\1cs_,g' -e 's,\<\(c\.\(default_\)\?\)other_,\1a_,g' kallithea/controllers/pullrequests.py kallithea/templates/pullrequests/pullrequest.html kallithea/templates/pullrequests/pullrequest_show.html kallithea/templates/changeset/diff_block.html
Renaming it differently for compare and PR finally fixes some issues with diffs and links pointing at wrong revisions and repos - no more whac-a-mole.
|
|
|
Mads Kiilerich
|
296b37f6fcdc
|
11 years ago
|
|
pull requests: load repo branch info on demand after changing repo
Visiting a lot of repositories for no reason takes time.
|
|
|
Mads Kiilerich
|
44ae84b422ad
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
e271a8766951
|
11 years ago
|
|
javascript: replace YUE.onDOMReady with $(document).ready
Different execution order of YUE.onDOMReady and $(document).ready makes it hard to do gradually.
|
|
|
Mads Kiilerich
|
cc5300a1f2ac
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
67d5afe2fa1a
|
12 years ago
|
|
|
|
|
Mads Kiilerich
|
486cd40776c2
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
29aa65c9638d
|
12 years ago
|
|
|
|
|
Mads Kiilerich
|
33a58b74bbc3
|
12 years ago
|
|
|
|
|
Mads Kiilerich
|
c2e3923eebe4
|
12 years ago
|
|
|
|
|
Mads Kiilerich
|
52f69be09fe1
|
12 years ago
|
|
|
|
|
Mads Kiilerich
|
bf011c9f7f58
|
12 years ago
|
|
|
|
|
Bradley M. Kuhn
|
9581233e9275
|
11 years ago
|
|
|
|
|
Bradley M. Kuhn
|
d1addaf7a91e
|
11 years ago
|
|
Second step in two-part process to rename directories. This is the actual directory rename.
|