Mercurial > hg
annotate tests/test-revset-dirstate-parents.t @ 30766:d7bf7d2bd5ab
hgweb: support Content Security Policy
Content-Security-Policy (CSP) is a web security feature that allows
servers to declare what loaded content is allowed to do. For example,
a policy can prevent loading of images, JavaScript, CSS, etc unless
the source of that content is whitelisted (by hostname, URI scheme,
hashes of content, etc). It's a nifty security feature that provides
extra mitigation against some attacks, notably XSS.
Mitigation against these attacks is important for Mercurial because
hgweb renders repository data, which is commonly untrusted. While we
make attempts to escape things, etc, there's the possibility that
malicious data could be injected into the site content. If this happens
today, the full power of the web browser is available to that
malicious content. A restrictive CSP policy (defined by the server
operator and sent in an HTTP header which is outside the control of
malicious content), could restrict browser capabilities and mitigate
security problems posed by malicious data.
CSP works by emitting an HTTP header declaring the policy that browsers
should apply. Ideally, this header would be emitted by a layer above
Mercurial (likely the HTTP server doing the WSGI "proxying"). This
works for some CSP policies, but not all.
For example, policies to allow inline JavaScript may require setting
a "nonce" attribute on <script>. This attribute value must be unique
and non-guessable. And, the value must be present in the HTTP header
and the HTML body. This means that coordinating the value between
Mercurial and another HTTP server could be difficult: it is much
easier to generate and emit the nonce in a central location.
This commit introduces support for emitting a
Content-Security-Policy header from hgweb. A config option defines
the header value. If present, the header is emitted. A special
"%nonce%" syntax in the value triggers generation of a nonce and
inclusion in <script> elements in templates. The inclusion of a
nonce does not occur unless "%nonce%" is present. This makes this
commit completely backwards compatible and the feature opt-in.
The nonce is a type 4 UUID, which is the flavor that is randomly
generated. It has 122 random bits, which should be plenty to satisfy
the guarantees of a nonce.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 10 Jan 2017 23:37:08 -0800 |
parents | 7d87f672d069 |
children | 7bbc4e113e5f |
rev | line source |
---|---|
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
1 $ HGENCODING=utf-8 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
2 $ export HGENCODING |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
3 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
4 $ try() { |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
5 > hg debugrevspec --debug $@ |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
6 > } |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
7 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
8 $ log() { |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
9 > hg log --template '{rev}\n' -r "$1" |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
10 > } |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
11 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
12 $ hg init repo |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
13 $ cd repo |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
14 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
15 $ try 'p1()' |
16218
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
12936
diff
changeset
|
16 (func |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
12936
diff
changeset
|
17 ('symbol', 'p1') |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
12936
diff
changeset
|
18 None) |
24458
7d87f672d069
debugrevspec: show nesting structure of smartsets if verbose
Yuya Nishihara <yuya@tcha.org>
parents:
16913
diff
changeset
|
19 * set: |
7d87f672d069
debugrevspec: show nesting structure of smartsets if verbose
Yuya Nishihara <yuya@tcha.org>
parents:
16913
diff
changeset
|
20 <baseset []> |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
21 $ try 'p2()' |
16218
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
12936
diff
changeset
|
22 (func |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
12936
diff
changeset
|
23 ('symbol', 'p2') |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
12936
diff
changeset
|
24 None) |
24458
7d87f672d069
debugrevspec: show nesting structure of smartsets if verbose
Yuya Nishihara <yuya@tcha.org>
parents:
16913
diff
changeset
|
25 * set: |
7d87f672d069
debugrevspec: show nesting structure of smartsets if verbose
Yuya Nishihara <yuya@tcha.org>
parents:
16913
diff
changeset
|
26 <baseset []> |
12935
98b79c892768
revset: fix p1, p2 and parents in dirstate case (a5f7f1e9340e)
Patrick Mezard <pmezard@gmail.com>
parents:
12929
diff
changeset
|
27 $ try 'parents()' |
16218
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
12936
diff
changeset
|
28 (func |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
12936
diff
changeset
|
29 ('symbol', 'parents') |
81a1a00f5738
debugrevspec: pretty print output
Patrick Mezard <patrick@mezard.eu>
parents:
12936
diff
changeset
|
30 None) |
24458
7d87f672d069
debugrevspec: show nesting structure of smartsets if verbose
Yuya Nishihara <yuya@tcha.org>
parents:
16913
diff
changeset
|
31 * set: |
7d87f672d069
debugrevspec: show nesting structure of smartsets if verbose
Yuya Nishihara <yuya@tcha.org>
parents:
16913
diff
changeset
|
32 <baseset+ []> |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
33 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
34 null revision |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
35 $ log 'p1()' |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
36 $ log 'p2()' |
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
37 $ log 'parents()' |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
38 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
39 working dir with a single parent |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
40 $ echo a > a |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
41 $ hg ci -Aqm0 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
42 $ log 'p1()' |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
43 0 |
12935
98b79c892768
revset: fix p1, p2 and parents in dirstate case (a5f7f1e9340e)
Patrick Mezard <pmezard@gmail.com>
parents:
12929
diff
changeset
|
44 $ log 'tag() and p1()' |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
45 $ log 'p2()' |
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
46 $ log 'parents()' |
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
47 0 |
12935
98b79c892768
revset: fix p1, p2 and parents in dirstate case (a5f7f1e9340e)
Patrick Mezard <pmezard@gmail.com>
parents:
12929
diff
changeset
|
48 $ log 'tag() and parents()' |
12928
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
49 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
50 merge in progress |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
51 $ echo b > b |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
52 $ hg ci -Aqm1 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
53 $ hg up -q 0 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
54 $ echo c > c |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
55 $ hg ci -Aqm2 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
56 $ hg merge -q |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
57 $ log 'p1()' |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
58 2 |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
59 $ log 'p2()' |
a5f7f1e9340e
revsets: let p1() and p2() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
diff
changeset
|
60 1 |
12935
98b79c892768
revset: fix p1, p2 and parents in dirstate case (a5f7f1e9340e)
Patrick Mezard <pmezard@gmail.com>
parents:
12929
diff
changeset
|
61 $ log 'tag() and p2()' |
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
62 $ log 'parents()' |
12935
98b79c892768
revset: fix p1, p2 and parents in dirstate case (a5f7f1e9340e)
Patrick Mezard <pmezard@gmail.com>
parents:
12929
diff
changeset
|
63 1 |
12929
515c2786e1cf
revsets: let parents() return parents of working dir
Kevin Bullock <kbullock@ringworld.org>
parents:
12928
diff
changeset
|
64 2 |
16913
f2719b387380
tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents:
16218
diff
changeset
|
65 |
f2719b387380
tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents:
16218
diff
changeset
|
66 $ cd .. |