XRootD
XrdOucUtils.cc File Reference
#include <cctype>
#include <grp.h>
#include <cstdio>
#include <list>
#include <vector>
#include <unordered_set>
#include <algorithm>
#include <fcntl.h>
#include <pwd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <map>
#include "XrdNet/XrdNetUtils.hh"
#include "XrdOuc/XrdOucCRC.hh"
#include "XrdOuc/XrdOucEnv.hh"
#include "XrdOuc/XrdOucSHA3.hh"
#include "XrdOuc/XrdOucStream.hh"
#include "XrdOuc/XrdOucString.hh"
#include "XrdOuc/XrdOucUtils.hh"
#include "XrdOuc/XrdOucPrivateUtils.hh"
#include "XrdSys/XrdSysE2T.hh"
#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysPlatform.hh"
#include "XrdSys/XrdSysPthread.hh"
+ Include dependency graph for XrdOucUtils.cc:

Go to the source code of this file.

Macros

#define ENODATA   ENOATTR
 
#define SHFT(k)   if (n >= (1ULL << k)) { i += k; n >>= k; }
 
#define SHFT(k, m)   if (n >= m) { i += k; n /= m; }
 

Functions

std::string obfuscate (const std::string &input, const std::vector< std::regex > &regexes)
 
std::string obfuscateAuth (const std::string &input)
 

Variables

static const std::vector< std::regex > authObfuscationRegexes
 
static const std::string OBFUSCATION_STR = "REDACTED"
 

Macro Definition Documentation

◆ ENODATA

#define ENODATA   ENOATTR

Definition at line 63 of file XrdOucUtils.cc.

◆ SHFT [1/2]

#define SHFT (   k)    if (n >= (1ULL << k)) { i += k; n >>= k; }

◆ SHFT [2/2]

#define SHFT (   k,
 
)    if (n >= m) { i += k; n /= m; }

Function Documentation

◆ obfuscate()

std::string obfuscate ( const std::string &  input,
const std::vector< std::regex > &  regexes 
)

Use this function to obfuscate any string containing key-values with OBFUSCATION_STR

Parameters
inputthe string to obfuscate
regexesthe obfuscation regexes to apply to replace the value with OBFUSCATION_STR. The key should be a regex group e.g: "(authz=)" Have a look at obfuscateAuth for more examples
Returns
the string with values obfuscated

Definition at line 1439 of file XrdOucUtils.cc.

1439  {
1440  std::string result = input;
1441  for(const auto & regex: regexes) {
1442  //Loop over the regexes and replace the values with OBFUSCATION_STR
1443  //$1 matches the first regex subgroup (e.g: "(authz=)")
1444  result = std::regex_replace(result, regex, std::string("$1" + OBFUSCATION_STR));
1445  }
1446  return result;
1447 }
static const std::string OBFUSCATION_STR
Definition: XrdOucUtils.cc:118

References OBFUSCATION_STR.

Referenced by obfuscateAuth().

+ Here is the caller graph for this function:

◆ obfuscateAuth()

std::string obfuscateAuth ( const std::string &  input)

PRIVATE HEADER for utility functions, implementation in XrdOucUtils.cc Obfuscates strings containing "authz=value", "Authorization: value", "TransferHeaderAuthorization: value", "WhateverAuthorization: value" in a case insensitive way.

Parameters
inputthe string to obfuscate

Definition at line 1449 of file XrdOucUtils.cc.

1449  {
1450  return obfuscate(input, authObfuscationRegexes);
1451 }
static const std::vector< std::regex > authObfuscationRegexes
Definition: XrdOucUtils.cc:123
std::string obfuscate(const std::string &input, const std::vector< std::regex > &regexes)

References authObfuscationRegexes, and obfuscate().

Referenced by XrdPfc::Cache::Attach(), XrdCl::URL::FromString(), XrdCl::URL::GetObfuscatedURL(), XrdCl::Utils::LogPropertyList(), main(), XrdHttpProtocol::Process(), XrdHttpReq::ProcessHTTPReq(), and XrdCl::Message::SetDescription().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ authObfuscationRegexes

const std::vector<std::regex> authObfuscationRegexes
static
Initial value:
= {
std::regex(R"((authz=)(Bearer\s)?([^ &\",<>#%{}|\^~\[\]`]*))",std::regex_constants::optimize),
std::regex(R"((\s*\w*Authorization\s*:\s*)[^$]*)", std::regex_constants::icase | std::regex_constants::optimize)
}

Definition at line 123 of file XrdOucUtils.cc.

Referenced by obfuscateAuth().

◆ OBFUSCATION_STR

const std::string OBFUSCATION_STR = "REDACTED"
static

Definition at line 118 of file XrdOucUtils.cc.

Referenced by obfuscate().