diff options
author | Jason A. Donenfeld | 2016-01-14 14:53:28 +0100 |
---|---|---|
committer | Jason A. Donenfeld | 2016-01-14 15:42:56 +0100 |
commit | c326f3eb026d67650f79a6dda9a1a42c55d10a25 (patch) | |
tree | 51b94c63164ea924eb019c2e3c1e0b290509549b | |
parent | 9ca2566972db968df4479108b29bb92551138b57 (diff) | |
download | cgit-c326f3eb026d67650f79a6dda9a1a42c55d10a25.tar.gz cgit-c326f3eb026d67650f79a6dda9a1a42c55d10a25.tar.bz2 cgit-c326f3eb026d67650f79a6dda9a1a42c55d10a25.zip |
ui-plain: add enable-html-serving flag
Unrestricts plain/ to contents likely to be executed by browser.
-rw-r--r-- | cgit.c | 5 | ||||
-rw-r--r-- | cgit.h | 2 | ||||
-rw-r--r-- | cgitrc.5.txt | 11 | ||||
-rw-r--r-- | shared.c | 1 | ||||
-rw-r--r-- | ui-plain.c | 10 |
5 files changed, 29 insertions, 0 deletions
@@ -55,6 +55,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va | |||
55 | repo->enable_remote_branches = atoi(value); | 55 | repo->enable_remote_branches = atoi(value); |
56 | else if (!strcmp(name, "enable-subject-links")) | 56 | else if (!strcmp(name, "enable-subject-links")) |
57 | repo->enable_subject_links = atoi(value); | 57 | repo->enable_subject_links = atoi(value); |
58 | else if (!strcmp(name, "enable-html-serving")) | ||
59 | repo->enable_html_serving = atoi(value); | ||
58 | else if (!strcmp(name, "branch-sort")) { | 60 | else if (!strcmp(name, "branch-sort")) { |
59 | if (!strcmp(value, "age")) | 61 | if (!strcmp(value, "age")) |
60 | repo->branch_sort = 1; | 62 | repo->branch_sort = 1; |
@@ -170,6 +172,8 @@ static void config_cb(const char *name, const char *value) | |||
170 | ctx.cfg.enable_remote_branches = atoi(value); | 172 | ctx.cfg.enable_remote_branches = atoi(value); |
171 | else if (!strcmp(name, "enable-subject-links")) | 173 | else if (!strcmp(name, "enable-subject-links")) |
172 | ctx.cfg.enable_subject_links = atoi(value); | 174 | ctx.cfg.enable_subject_links = atoi(value); |
175 | else if (!strcmp(name, "enable-html-serving")) | ||
176 | ctx.cfg.enable_html_serving = atoi(value); | ||
173 | else if (!strcmp(name, "enable-tree-linenumbers")) | 177 | else if (!strcmp(name, "enable-tree-linenumbers")) |
174 | ctx.cfg.enable_tree_linenumbers = atoi(value); | 178 | ctx.cfg.enable_tree_linenumbers = atoi(value); |
175 | else if (!strcmp(name, "enable-git-config")) | 179 | else if (!strcmp(name, "enable-git-config")) |
@@ -821,6 +825,7 @@ static void print_repo(FILE *f, struct cgit_repo *repo) | |||
821 | fprintf(f, "repo.logo-link=%s\n", repo->logo_link); | 825 | fprintf(f, "repo.logo-link=%s\n", repo->logo_link); |
822 | fprintf(f, "repo.enable-remote-branches=%d\n", repo->enable_remote_branches); | 826 | fprintf(f, "repo.enable-remote-branches=%d\n", repo->enable_remote_branches); |
823 | fprintf(f, "repo.enable-subject-links=%d\n", repo->enable_subject_links); | 827 | fprintf(f, "repo.enable-subject-links=%d\n", repo->enable_subject_links); |
828 | fprintf(f, "repo.enable-html-serving=%d\n", repo->enable_html_serving); | ||
824 | if (repo->branch_sort == 1) | 829 | if (repo->branch_sort == 1) |
825 | fprintf(f, "repo.branch-sort=age\n"); | 830 | fprintf(f, "repo.branch-sort=age\n"); |
826 | if (repo->commit_sort) { | 831 | if (repo->commit_sort) { |
@@ -101,6 +101,7 @@ struct cgit_repo { | |||
101 | int enable_log_linecount; | 101 | int enable_log_linecount; |
102 | int enable_remote_branches; | 102 | int enable_remote_branches; |
103 | int enable_subject_links; | 103 | int enable_subject_links; |
104 | int enable_html_serving; | ||
104 | int max_stats; | 105 | int max_stats; |
105 | int branch_sort; | 106 | int branch_sort; |
106 | int commit_sort; | 107 | int commit_sort; |
@@ -235,6 +236,7 @@ struct cgit_config { | |||
235 | int enable_log_linecount; | 236 | int enable_log_linecount; |
236 | int enable_remote_branches; | 237 | int enable_remote_branches; |
237 | int enable_subject_links; | 238 | int enable_subject_links; |
239 | int enable_html_serving; | ||
238 | int enable_tree_linenumbers; | 240 | int enable_tree_linenumbers; |
239 | int enable_git_config; | 241 | int enable_git_config; |
240 | int local_time; | 242 | int local_time; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 759f353..47850a8 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -190,6 +190,13 @@ enable-subject-links:: | |||
190 | in commit view. Default value: "0". See also: | 190 | in commit view. Default value: "0". See also: |
191 | "repo.enable-subject-links". | 191 | "repo.enable-subject-links". |
192 | 192 | ||
193 | enable-html-serving:: | ||
194 | Flag which, when set to "1", will allow the /plain handler to serve | ||
195 | mimetype headers that result in the file being treated as HTML by the | ||
196 | browser. When set to "0", such file types are returned instead as | ||
197 | text/plain or application/octet-stream. Default value: "0". See also: | ||
198 | "repo.enable-html-serving". | ||
199 | |||
193 | enable-tree-linenumbers:: | 200 | enable-tree-linenumbers:: |
194 | Flag which, when set to "1", will make cgit generate linenumber links | 201 | Flag which, when set to "1", will make cgit generate linenumber links |
195 | for plaintext blobs printed in the tree view. Default value: "1". | 202 | for plaintext blobs printed in the tree view. Default value: "1". |
@@ -513,6 +520,10 @@ repo.enable-subject-links:: | |||
513 | A flag which can be used to override the global setting | 520 | A flag which can be used to override the global setting |
514 | `enable-subject-links'. Default value: none. | 521 | `enable-subject-links'. Default value: none. |
515 | 522 | ||
523 | enable-html-serving:: | ||
524 | A flag which can be used to override the global setting | ||
525 | `enable-html-serving`. Default value: none. | ||
526 | |||
516 | repo.hide:: | 527 | repo.hide:: |
517 | Flag which, when set to "1", hides the repository from the repository | 528 | Flag which, when set to "1", hides the repository from the repository |
518 | index. The repository can still be accessed by providing a direct path. | 529 | index. The repository can still be accessed by providing a direct path. |
@@ -61,6 +61,7 @@ struct cgit_repo *cgit_add_repo(const char *url) | |||
61 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; | 61 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
62 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; | 62 | ret->enable_remote_branches = ctx.cfg.enable_remote_branches; |
63 | ret->enable_subject_links = ctx.cfg.enable_subject_links; | 63 | ret->enable_subject_links = ctx.cfg.enable_subject_links; |
64 | ret->enable_html_serving = ctx.cfg.enable_html_serving; | ||
64 | ret->max_stats = ctx.cfg.max_stats; | 65 | ret->max_stats = ctx.cfg.max_stats; |
65 | ret->branch_sort = ctx.cfg.branch_sort; | 66 | ret->branch_sort = ctx.cfg.branch_sort; |
66 | ret->commit_sort = ctx.cfg.commit_sort; | 67 | ret->commit_sort = ctx.cfg.commit_sort; |
@@ -37,6 +37,16 @@ static int print_object(const unsigned char *sha1, const char *path) | |||
37 | mimetype = get_mimetype_for_filename(path); | 37 | mimetype = get_mimetype_for_filename(path); |
38 | ctx.page.mimetype = mimetype; | 38 | ctx.page.mimetype = mimetype; |
39 | 39 | ||
40 | if (!ctx.repo->enable_html_serving) { | ||
41 | html("X-Content-Type-Options: nosniff\n"); | ||
42 | html("Content-Security-Policy: default-src 'none'\n"); | ||
43 | if (mimetype) { | ||
44 | /* Built-in white list allows PDF and everything that isn't text/ and application/ */ | ||
45 | if ((!strncmp(mimetype, "text/", 5) || !strncmp(mimetype, "application/", 12)) && strcmp(mimetype, "application/pdf")) | ||
46 | ctx.page.mimetype = NULL; | ||
47 | } | ||
48 | } | ||
49 | |||
40 | if (!ctx.page.mimetype) { | 50 | if (!ctx.page.mimetype) { |
41 | if (buffer_is_binary(buf, size)) { | 51 | if (buffer_is_binary(buf, size)) { |
42 | ctx.page.mimetype = "application/octet-stream"; | 52 | ctx.page.mimetype = "application/octet-stream"; |