summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@redhat.com>2020-01-11 16:05:46 -0500
committerFrank Ch. Eigler <fche@redhat.com>2020-01-11 16:05:46 -0500
commit05429d753116f5c2931dc15d6cc2a25b310a9f49 (patch)
tree516a741071c8966aac98121f1d7089163f60d7ef
parent32ed4e6f8e827949d9c2a16c5fbc0aa75a6a4da9 (diff)
downloadelfutils-05429d753116f5c2931dc15d6cc2a25b310a9f49.tar.gz
debuginfod: print U-A: and X-F-F: request headers
For an incoming webapi request, print two headers that should assist in the administration of a debuginfod service. At fweimer's suggestion, added a bit of filtering so the text is more reliably parseable. Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
-rw-r--r--debuginfod/ChangeLog6
-rw-r--r--debuginfod/debuginfod.cxx23
2 files changed, 26 insertions, 3 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 4167215f..795b617b 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,5 +1,11 @@
2020-01-11 Frank Ch. Eigler <fche@redhat.com>
+ * debuginfod.cxx (conninfo): Print User-Agent and X-Forwarded-For
+ request headers, after mild safety-censorship (for easier machine
+ processing).
+
+2020-01-11 Frank Ch. Eigler <fche@redhat.com>
+
* debuginfod.cxx: Rework threading model.
(workq): New class for concurrent work-queue.
(semaphore): Removed class, now unused.
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 05fbacc2..1c60e8d3 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -1,5 +1,5 @@
/* Debuginfo-over-http server.
- Copyright (C) 2019 Red Hat, Inc.
+ Copyright (C) 2019-2020 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -742,7 +742,17 @@ private:
////////////////////////////////////////////////////////////////////////
-
+static string
+header_censor(const string& str)
+{
+ string y;
+ for (auto&& x : str)
+ {
+ if (isalnum(x) || x == '/' || x == '.' || x == ',' || x == '_' || x == ':')
+ y += x;
+ }
+ return y;
+}
static string
@@ -771,7 +781,14 @@ conninfo (struct MHD_Connection * conn)
hostname[0] = servname[0] = '\0';
}
- return string(hostname) + string(":") + string(servname);
+ // extract headers relevant to administration
+ const char* user_agent = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "User-Agent") ?: "";
+ const char* x_forwarded_for = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "X-Forwarded-For") ?: "";
+ // NB: these are untrustworthy, beware if machine-processing log files
+
+ return string(hostname) + string(":") + string(servname) +
+ string(" UA:") + header_censor(string(user_agent)) +
+ string(" XFF:") + header_censor(string(x_forwarded_for));
}