git repos / sago_web_git

commit 3f3d49d0

Poul Sander · 2026-07-11 12:32
3f3d49d009ea2a00c03d764068d0e4db3cb71833 patch · browse files
parent 5241fe95285e7a1c623c7bb6bfcc7f15a7e31330

Add robots txt to discourage access to "blame".

Changed files

M src/application.cpp before
M src/application.h before
diff --git a/src/application.cpp b/src/application.cpp index 41a8122..57364d2 100644 --- a/src/application.cpp +++ b/src/application.cpp
@@ -122,6 +122,7 @@ GitApp::GitApp(cppcms::service &srv, const RepoScanner *scanner)
allow_clone_ = resolve_allow_clone(settings().get<bool>("git.allow_clone", false));
// Root arrives as "" because script_name "/" is stripped; accept both.
+ dispatcher().assign(R"(^/robots\.txt$)", &GitApp::robots_txt, this);
dispatcher().assign("^/?$", &GitApp::frontpage, this);
dispatcher().assign("^/about/?$", &GitApp::about, this);
dispatcher().assign("^/static/(.+)$", &GitApp::static_file, this, 1);
@@ -131,10 +132,10 @@ GitApp::GitApp(cppcms::service &srv, const RepoScanner *scanner)
dispatcher().assign("^/repos/([^/]+)/blame/(.+)$", &GitApp::blame, this, 1, 2);
dispatcher().assign("^/repos/([^/]+)/object/([0-9a-f]+)$", &GitApp::object, this, 1, 2);
dispatcher().assign("^/repos/([^/]+)/log/?$", &GitApp::log, this, 1);
- dispatcher().assign("^/repos/([^/]+)/commit/([0-9a-f]+)\\.patch$", &GitApp::commit_patch, this, 1, 2);
+ dispatcher().assign(R"(^/repos/([^/]+)/commit/([0-9a-f]+)\.patch$)", &GitApp::commit_patch, this, 1, 2);
dispatcher().assign("^/repos/([^/]+)/commit/([0-9a-f]+)$", &GitApp::commit, this, 1, 2);
dispatcher().assign("^/repos/([^/]+)/tags/?$", &GitApp::tags, this, 1);
- dispatcher().assign("^/repos/([^/]+)/tags/(.+)\\.tar\\.gz$", &GitApp::tag_archive, this, 1, 2);
+ dispatcher().assign(R"(^/repos/([^/]+)/tags/(.+)\.tar\.gz$)", &GitApp::tag_archive, this, 1, 2);
dispatcher().assign("^/repos/([^/]+)/tags/(.+)$", &GitApp::tag, this, 1, 2);
dispatcher().assign("^/repos/([^/]+)/branches/?$", &GitApp::branches, this, 1);
// Only wire up the clone endpoints when enabled, so a disabled server never
@@ -160,6 +161,13 @@ void GitApp::main(std::string url) {
cppcms::application::main(url);
}
+void GitApp::robots_txt() {
+ response().content_type("text/plain; charset=utf-8");
+ response().out() << "User-agent: *\n"
+ "Disallow: /repos/*/blame/\n"
+ "Allow: /\n";
+}
+
void GitApp::static_file(std::string rel) {
if (rel.find("..") != std::string::npos) {
show_error(403, "Forbidden");
diff --git a/src/application.h b/src/application.h index a606504..338cfc3 100644 --- a/src/application.h +++ b/src/application.h
@@ -60,6 +60,7 @@ private:
void branches(std::string name);
void commit(std::string name, std::string oid);
void commit_patch(std::string name, std::string oid);
+ void robots_txt();
void static_file(std::string rel);
// Serves Git's Smart HTTP protocol (clone/fetch) by proxying to