|
|
Mads Kiilerich
|
64cc63e186e6
|
5 years ago
|
|
|
|
|
Mads Kiilerich
|
19d93bd709bf
|
5 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
|
35af0bd45bf3
|
5 years ago
|
|
diff: drop per file ignore-whitespace and context - it didn't work and had conceptual issue (Issue #344)
Diffs are currently generated at the low level as one big diff between two vcs resisions, provided global values for diff context size and flag for ignoring whitespace. All files use the same flags. There is no way to actually compute the full diff using these use per file flags, and no simple and efficient way to add it.
The best option is thus to drop the failed attempt at making it per file, and just rely on the simple global flags in the URL.
The links for changing whitespace and context is sometimes shown for the whole "page", and sometimes next to the diff for one file. For now, keep showing the link in these places, but make sure it navigates back to the FID of the section where the link was clicked.
The implementation is completely rewritten and moved to a more appropriate location in helpers.
With a more clean implementation, we also consistently use the simple getters to extract values from the URL.
|
|
|
Mads Kiilerich
|
ec4e69a60aae
|
5 years ago
|
|
html: fix invalid html / mako structure
Fix bad nesting of tags and mako conditional and drop superfluous '}' outside the mako block.
|
|
|
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
|
e35373106528
|
6 years ago
|
|
py3: remove safe_unicode in places where it no longer is needed because all strings (except bytes) already *are* unicode strings
(The remaining safe_unicode calls are still needed and can't just be removed, generally because we in these cases still have to convert from bytes to unicode strings.)
|
|
|
Thomas De Schampheleire
|
9f41dc6f328a
|
7 years ago
|
|
|
|
|
Mads Kiilerich
|
e08c2b38ae0d
|
7 years ago
|
|
compare: correct display of special branch names in initial placeholder When a branch name contains special characters like '<' or '>', and a 'compare' operation is performed with such branch as one of the two compare sides, then the special branch name will be part of the URL, e.g. http://localhost:5000/myrepo/compare/branch@master...branch@%3Cscript%3Eblabla%3C/script%3E?other_repo=myrepoThe encoded branch name is then used at page load as placeholders for the branch selection dropdowns. But, the special characters, were escaped too much, causing '<' to become < in the display of the dropdown. It was not correct to use h.jshtml() to escape in the template. That applied html formatting, too much and too early. We want the raw value. h.js() gives us that, while still formatting and escaping the string so it is safe inside the script tag.
|
|
|
Thomas De Schampheleire
|
a8d873e9cab0
|
7 years ago
|
|
compare: prevent XSS due to unescaped branch/tag/bookmark names
In the revision selection dropdown of the 'Compare' functionality, the branch/tag/bookmark names were not correctly escaped.
This means that if an attacker is able to push a branch/tag/bookmark containing HTML/JavaScript in its name, then that code would be evaluated. This is a cross-site scripting (XSS) vulnerability.
Fix the problem by correctly escaping the branch/tag/bookmarks.
|
|
|
Mads Kiilerich
|
9376ca7157f3
|
7 years ago
|
|
compare: correct display of special branch names in initial placeholder When a branch name contains special characters like '<' or '>', and a 'compare' operation is performed with such branch as one of the two compare sides, then the special branch name will be part of the URL, e.g. http://localhost:5000/myrepo/compare/branch@master...branch@%3Cscript%3Eblabla%3C/script%3E?other_repo=myrepoThe encoded branch name is then used at page load as placeholders for the branch selection dropdowns. But, the special characters, were escaped too much, causing '<' to become < in the display of the dropdown. The placeholder was escaped via the default mako escape filter, before being passed to make_revision_dropdown, thus too early. We want the raw value. h.js() (copied from the default branch) gives us that, while still formatting and escaping the string so it is safe inside the script tag.
|
|
|
Thomas De Schampheleire
|
04e44ea05c5f
|
7 years ago
|
|
compare: prevent XSS due to unescaped branch/tag/bookmark names
In the revision selection dropdown of the 'Compare' functionality, the branch/tag/bookmark names were not correctly escaped.
This means that if an attacker is able to push a branch/tag/bookmark containing HTML/JavaScript in its name, then that code would be evaluated. This is a cross-site scripting (XSS) vulnerability.
Fix the problem by correctly escaping the branch/tag/bookmarks.
|
|
|
domruf
|
2d8f2a419edb
|
8 years ago
|
|
style: remove whitespace after icons
Where the additional spacing is needed, we already have a padding-right, so these spaces are unnecessary. But more importantly they cause trouble if text-decoration is used (i.e. underline on hover).
|
|
|
domruf
|
647e7e0ce812
|
8 years ago
|
|
|
|
|
domruf
|
b66e4d720198
|
8 years ago
|
|
templates: change .node elements to <span>
This way we don't need to make them 'float: left'
|
|
|
domruf
|
73234a550e7d
|
8 years ago
|
|
templates: remove redundant pull-left and pull-right for changeset progress bars
"float: left" and "float: right" for these elements are already set in kallithea-diff.less.
Aligns it with compare_diff.html which already didn't use "pull" on "node" and "changes".
|
|
|
domruf
|
3fca87aa2b15
|
8 years ago
|
|
templates: don't use ordinary elements as links or buttons by adding btn styling
Bootstrap recommends using <button>, so most of the time we should use that.
Extracted by Mads Kiilerich.
|
|
|
domruf
|
6f38405ed2f2
|
8 years ago
|
|
templates: use span for inline elements
Instead of using div and making it an inline elment with css use span which already is a inline element.
|
|
|
Mads Kiilerich
|
5e3adb20839d
|
8 years ago
|
|
style: replace code-body etc with Bootstrap-ish panel and panel-heading, using panel-default for headers and tweak them grey
Based on work by Dominik Ruf.
|
|
|
Søren Løvborg
|
3c720eeaca89
|
9 years ago
|
|
compare: refactor drop-down UI code
Don't rely on fake ref_names in the controller; instead put the code in the HTML together with the other UI code.
|
|
|
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.
|
|
|
Søren Løvborg
|
4e9caabef69c
|
9 years ago
|
|
|
|
|
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
|
d99afb88579e
|
9 years ago
|
|
style: rename div.table to Bootstrap .panel-body
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
41dd3c2f820c
|
9 years ago
|
|
style: introduce h2 h3 h4 h5 for emphasis and drop some explicit styling
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
8656c0073e17
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
1cf51cd05e36
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
a810db90098e
|
9 years ago
|
|
style: use Bootstrap compatible "text-muted" class
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
33ca6d0f7058
|
9 years ago
|
|
style: introduce "clearfix" class where the Bootstrap migration will need it
Based on work by Dominik Ruf.
|
|
|
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
|
12ce88eece5f
|
9 years ago
|
|
diff: correct handling of links to old filename in renames
There were links to the file at the parent revision ... but if the file had been renamed, it used the wrong name.
|
|
|
Mads Kiilerich
|
4034992774fa
|
9 years ago
|
|
diffs: fold diff_block_simple (used by PR and compare) into diff_block
Change to using the same datamodel and enjoy the reduced amount of code duplication.
|
|
|
Mads Kiilerich
|
72acb38da217
|
9 years ago
|
|
diff: minor cleanups
More consistency and preparing for later changes.
|
|
|
Mads Kiilerich
|
cc18e56220a2
|
9 years ago
|
|
compare: improve select2 performance with many branches
Like elsewhere for pure branch selectors.
|
|
|
Jan Heylen
|
150431aae9ba
|
10 years ago
|
|
diff: move looping over files into diff_block_simple
Make it slightly more like regular diff_block and make the next changes possible.
|
|
|
Søren Løvborg
|
feef81a369b3
|
10 years ago
|
|
compare: clean up revision selector HTML/CSS
This fixes margins and vertical alignment.
|
|
|
Søren Løvborg
|
4b9370a01c4d
|
10 years ago
|
|
compare: fix 404 ("undefined" ref type) error
The changeset selector would create selector entries without the 'type' attribute when running in "cached" mode, causing 404 errors.
|
|
|
Søren Løvborg
|
047ac9eefb71
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
e729c2f03ba7
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
df5b6fc6c518
|
10 years ago
|
|
|
|
|
Sean Farley
|
e8ff151b3085
|
11 years ago
|
|
|
|
|
Thomas De Schampheleire
|
3a3ec35466e7
|
11 years ago
|
|
templates: move site branding in page title to base template
Instead of repeating the same three lines in each and every template, move it to the base template.
|
|
|
Mads Kiilerich
|
37354e1ab283
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
ec39e73be935
|
11 years ago
|
|
|
|
|
Sean Farley
|
de5f6c9f50b0
|
11 years ago
|
|
|
|
|
Sean Farley
|
dbf7341d10b1
|
11 years ago
|
|
|
|
|
Sean Farley
|
be3823704f21
|
11 years ago
|
|
arrow_inout.png: replace icon-loop with icon-git-compare
A quick search revealed that some old css code was never used, so it was removed.
|
|
|
Na'Tosha Bard
|
cadbabcc6b0e
|
11 years ago
|
|
Switch ellipses to right-arrow in header of compare page.
We use a right-arrow at the top of the file-diff sections. This makes the header do the same thing for consistency.
|
|
|
Na'Tosha Bard
|
dacdea9fda2a
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
b3f12c354e87
|
11 years ago
|
|
|
|
|
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
|
e457b951aabe
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
79eb3211cda1
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
60ae17de2a8d
|
12 years ago
|
|
|
|
|
Mads Kiilerich
|
60ea826baf09
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
c2e3923eebe4
|
12 years ago
|
|
|
|
|
Mads Kiilerich
|
bf011c9f7f58
|
12 years ago
|
|
|
|
|
Bradley M. Kuhn
|
a540f7e69c82
|
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.
|