]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod: print U-A: and X-F-F: request headers
authorFrank Ch. Eigler <fche@redhat.com>
Sat, 11 Jan 2020 21:05:46 +0000 (16:05 -0500)
committerFrank Ch. Eigler <fche@redhat.com>
Sat, 11 Jan 2020 21:05:46 +0000 (16:05 -0500)
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>
debuginfod/ChangeLog
debuginfod/debuginfod.cxx

index 4167215f2607dafc83ab8369d0e6d85329d8d991..795b617ba4e1c7741bbf46e6e3a57b4bb3c467fa 100644 (file)
@@ -1,3 +1,9 @@
+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.
index 05fbacc2b87383ac7ee2423221a09b3980d4a3bf..1c60e8d39e15eb195b8e390ada71ea4237515f27 100644 (file)
@@ -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));
 }