|
|
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
|
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
|
|
|
|
|
Patrick Vane
|
44f7f73da4a6
|
8 years ago
|
|
recaptcha: Update to Google recaptcha API v2 (Issue #313) Recaptcha stopped working. It was using google recaptcha v1, and https://developers.google.com/recaptcha/docs/faq says: "Any calls to the v1 API will not work after March 31, 2018." Note: 1) Not using 'async defer' - it's not used anywhere else, plus I have no idea of what exactly it does. 2) The recaptcha div has an ID so the label for="recaptcha_field" can reference it (although I'm not certain a div can technically have a label, but it's better than removing the label, or the for="").
|
|
|
domruf
|
919cebd1073c
|
8 years ago
|
|
templates: use bootstrap grid system for centered panels (login page etc.)
The bootstrap grid system rearranges the elements so that the pages look good an small screens as well. (i.e. no vertical scrolling)
|
|
|
domruf
|
1433199fb0f5
|
8 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.
|
|
|
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
|
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
|
ba18d1f6d081
|
9 years ago
|
|
style: refactor panel headings - use pull-left and pull-right and introduce clearfix like Bootstrap
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
8656c0073e17
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
a79e651306e2
|
9 years ago
|
|
style: add missing 'form-control' markup
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.
|
|
|
Mads Kiilerich
|
8a50208651c1
|
9 years ago
|
|
style: use Bootstrap compatible markup for alert
Based on work by Dominik Ruf.
|
|
|
Mads Kiilerich
|
6f4f39b21302
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
68d3315c48d4
|
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
|
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`
|
|
|
Andrew Shadura
|
f629e9a0c376
|
11 years ago
|
|
auth: secure password reset implementation
This is a better implementation of password reset function, which doesn't involve sending a new password to the user's email address in clear text, and at the same time is stateless.
The old implementation generated a new password and sent it in clear text to whatever email assigned to the user currently, so that any user, possibly unauthenticated, could request a reset for any username or email. Apart from potential insecurity, this made it possible for anyone to disrupt users' workflow by repeatedly resetting their passwords.
The idea behind this implementation is to generate an authentication token which is dependent on the user state at the time before the password change takes place, so the token is one-time and can't be reused, and also to bind the token to the browser session.
The token is calculated as SHA1 hash of the following:
* user's identifier (number, not a name) * timestamp * hashed user's password * session identifier * per-application secret
We use numeric user's identifier, as it's fixed and doesn't change, so renaming users doesn't affect the mechanism. Timestamp is added to make it possible to limit the token's validness (currently hard coded to 24h), and we don't want users to be able to fake that field easily. Hashed user's password is needed to prevent using the token again once the password has been changed. Session identifier is an additional security measure to ensure someone else stealing the token can't use it. Finally, per-application secret is just another way to make it harder for an attacker to guess all values in an attempt to generate a valid token.
When the token is generated, an anonymous user is directed to a confirmation page where the timestamp and the usernames are already preloaded, so the user needs to specify the token. User can either click the link in the email if it's really them reading it, or to type the token manually.
Using the right token in the same session as it was requested directs the user to a password change form, where the user is supposed to specify a new password (twice, of course). Upon completing the form (which is POSTed) the password change happens and a notification mail is sent.
The test is updated to test the basic functionality with a bad and a good token, but it doesn't (yet) cover all code paths.
The original work from Andrew has been thorougly reviewed and heavily modified by Søren Løvborg.
|
|
|
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
|
|
|
|
|
Mads Kiilerich
|
72bf89475004
|
11 years ago
|
|
styling: don't loop on loading kallithea-logo.png after kallithea-logo.svg failed
Bad configuration of static files or static_files=false could make the page loop when trying to apply the svg/png fallback.
Instead, let the error handler remove itself when it is used the first time.
|
|
|
Na'Tosha Bard
|
dacdea9fda2a
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
b3f12c354e87
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
34a7bec2c525
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
6f87a5ae84b7
|
11 years ago
|
|
|
|
|
Sean Farley
|
dd8f8f5895b2
|
11 years ago
|
|
|
|
|
Bradley M. Kuhn
|
24c0d584ba86
|
11 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.
|