Teamcenter C++ API Reference  2312
Static Public Member Functions | Static Private Attributes | List of all members
Teamcenter::Sanitizer Class Reference

#include <Sanitizer.hxx>

Static Public Member Functions

static std::string sanitizeCommand (const std::string &theInput)
 
static std::string sanitizePath (const std::string &theInput)
 
static std::string sanitizePathWithWhiteList (std::vector< std::string > &whiteList, std::vector< std::string > &validExtensions, const std::string &theInput, bool ignoreCase=true)
 

Static Private Attributes

static std::string m_delimiters
 
static std::string m_invalidStringList2 []
 
static const int m_numInvalidStrings = 20
 

Detailed Description

Definition at line 23 of file Sanitizer.hxx.

Member Function Documentation

static std::string Teamcenter::Sanitizer::sanitizeCommand ( const std::string &  theInput)
static

Sanitize a user input string before including it in a command to be executed in another process or shell (e.g., with Runtime.exec()). The method is intended to detect and prevent command injection attacks. It checks whether the input string contains shell control characters or OS commands that might be signs of command injection.

Parameters
theInputthe user input string to be sanitized.
Returns
the input string if the string is judged to be safe for command execution.
Exceptions
SanitizationExceptionif the string is judged unsafe for command execution.
static std::string Teamcenter::Sanitizer::sanitizePath ( const std::string &  theInput)
static

Sanitize a user input string before it is included in a file path to be opened for read or write. The method is intended to detect and prevent file path traversal attacks. It checks that the input string is a relative path and does not contain character sequences such as "../.." that can traverse out of a base directory. For stronger validation handling symbolic links or if an absolute path is to be sanitized, the sanitizePathWithWhitelist method is recommended instead.

Parameters
theInputthe user input string to be sanitized.
Returns
the normalized version of input string if the string is judged to be free of path traversal attacks
Exceptions
SanitizationExceptionif the string is suspected for a path traversal attack as well as untrust absoulute path.
static std::string Teamcenter::Sanitizer::sanitizePathWithWhiteList ( std::vector< std::string > &  whiteList,
std::vector< std::string > &  validExtensions,
const std::string &  theInput,
bool  ignoreCase = true 
)
static

Sanitize a user input string before it is included in a file path to be opened for read or write. The method is intended to detect and prevent file path traversal attacks. It checks that the input string denotes a file that is either in the white list or is within a directory in the whitelist. If validExtensions is provided the file must also have an extension that is in the list. Unlike sanitizePath, the input to be sanitized is allowed to be an absolute path.

Parameters
whiteListuser input valid file path list to begin with
validExtensionsuser input valid file extension list to end with
theInputthe user input string to be sanitized.
ignoreCasePerform case insensitive path comparisons for theInput with whitelist and validExtensions values by default.
Returns
String the input string if the string is judged to be free of path/file attacks
Exceptions
SanitizationExceptionan Sanitization exception is thrown

Member Data Documentation

std::string Teamcenter::Sanitizer::m_delimiters
staticprivate

Definition at line 72 of file Sanitizer.hxx.

std::string Teamcenter::Sanitizer::m_invalidStringList2[]
staticprivate

Definition at line 74 of file Sanitizer.hxx.

const int Teamcenter::Sanitizer::m_numInvalidStrings = 20
staticprivate

Definition at line 73 of file Sanitizer.hxx.


The documentation for this class was generated from the following file: