ui-plain: add enable-html-serving flag Unrestricts plain/ to contents likely to be executed by browser.
Jason A. Donenfeld Jason@zx2c4.com
Thu, 14 Jan 2016 14:53:28 +0100
5 files changed,
29 insertions(+),
0 deletions(-)
M
cgit.c
→
cgit.c
@@ -55,6 +55,8 @@ else if (!strcmp(name, "enable-remote-branches"))
repo->enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) repo->enable_subject_links = atoi(value); + else if (!strcmp(name, "enable-html-serving")) + repo->enable_html_serving = atoi(value); else if (!strcmp(name, "branch-sort")) { if (!strcmp(value, "age")) repo->branch_sort = 1;@@ -170,6 +172,8 @@ else if (!strcmp(name, "enable-remote-branches"))
ctx.cfg.enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) ctx.cfg.enable_subject_links = atoi(value); + else if (!strcmp(name, "enable-html-serving")) + ctx.cfg.enable_html_serving = atoi(value); else if (!strcmp(name, "enable-tree-linenumbers")) ctx.cfg.enable_tree_linenumbers = atoi(value); else if (!strcmp(name, "enable-git-config"))@@ -821,6 +825,7 @@ if (repo->logo_link)
fprintf(f, "repo.logo-link=%s\n", repo->logo_link); fprintf(f, "repo.enable-remote-branches=%d\n", repo->enable_remote_branches); fprintf(f, "repo.enable-subject-links=%d\n", repo->enable_subject_links); + fprintf(f, "repo.enable-html-serving=%d\n", repo->enable_html_serving); if (repo->branch_sort == 1) fprintf(f, "repo.branch-sort=age\n"); if (repo->commit_sort) {
M
cgit.h
→
cgit.h
@@ -101,6 +101,7 @@ int enable_log_filecount;
int enable_log_linecount; int enable_remote_branches; int enable_subject_links; + int enable_html_serving; int max_stats; int branch_sort; int commit_sort;@@ -235,6 +236,7 @@ int enable_log_filecount;
int enable_log_linecount; int enable_remote_branches; int enable_subject_links; + int enable_html_serving; int enable_tree_linenumbers; int enable_git_config; int local_time;
M
cgitrc.5.txt
→
cgitrc.5.txt
@@ -190,6 +190,13 @@ parent commit as link text when generating links to parent commits
in commit view. Default value: "0". See also: "repo.enable-subject-links". +enable-html-serving:: + Flag which, when set to "1", will allow the /plain handler to serve + mimetype headers that result in the file being treated as HTML by the + browser. When set to "0", such file types are returned instead as + text/plain or application/octet-stream. Default value: "0". See also: + "repo.enable-html-serving". + enable-tree-linenumbers:: Flag which, when set to "1", will make cgit generate linenumber links for plaintext blobs printed in the tree view. Default value: "1".@@ -512,6 +519,10 @@
repo.enable-subject-links:: A flag which can be used to override the global setting `enable-subject-links'. Default value: none. + +enable-html-serving:: + A flag which can be used to override the global setting + `enable-html-serving`. Default value: none. repo.hide:: Flag which, when set to "1", hides the repository from the repository
M
ui-plain.c
→
ui-plain.c
@@ -37,6 +37,16 @@
mimetype = get_mimetype_for_filename(path); ctx.page.mimetype = mimetype; + if (!ctx.repo->enable_html_serving) { + html("X-Content-Type-Options: nosniff\n"); + html("Content-Security-Policy: default-src 'none'\n"); + if (mimetype) { + /* Built-in white list allows PDF and everything that isn't text/ and application/ */ + if ((!strncmp(mimetype, "text/", 5) || !strncmp(mimetype, "application/", 12)) && strcmp(mimetype, "application/pdf")) + ctx.page.mimetype = NULL; + } + } + if (!ctx.page.mimetype) { if (buffer_is_binary(buf, size)) { ctx.page.mimetype = "application/octet-stream";