Skip to content

Commit 0e2508b

Browse files
committed
Added masking of certain function arguments when using addDebugHook
1 parent 9e2b9ec commit 0e2508b

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Shared/mods/deathmatch/logic/CDebugHookManager.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
///////////////////////////////////////////////////////////////
2727
CDebugHookManager::CDebugHookManager( void )
2828
{
29+
#ifndef MTA_CLIENT
30+
m_MaskArgumentsMap["dbConnect"] = { 1, 2, 3 }; // type, 1=HOST, 2=USERNAME, 3=PASSWORD, options
31+
m_MaskArgumentsMap["logIn"] = { 2 }; // player, account, 2=PASSWORD
32+
m_MaskArgumentsMap["addAccount"] = { 1 }; // name, 1=PASSWORD
33+
m_MaskArgumentsMap["getAccount"] = { 1 }; // name, 1=PASSWORD
34+
m_MaskArgumentsMap["setAccountPassword"] = { 1 }; // account, 1=PASSWORD
35+
#endif
2936
}
3037

3138

@@ -219,6 +226,7 @@ bool CDebugHookManager::OnPreFunction( lua_CFunction f, lua_State* luaVM, bool b
219226

220227
CLuaArguments FunctionArguments;
221228
FunctionArguments.ReadArguments( luaVM );
229+
MaybeMaskArgumentValues( strName, FunctionArguments );
222230
NewArguments.PushArguments( FunctionArguments );
223231

224232
return CallHook( strName, m_PreFunctionHookList, NewArguments, bNameMustBeExplicitlyAllowed );
@@ -271,6 +279,7 @@ void CDebugHookManager::OnPostFunction( lua_CFunction f, lua_State* luaVM )
271279

272280
CLuaArguments FunctionArguments;
273281
FunctionArguments.ReadArguments( luaVM );
282+
MaybeMaskArgumentValues( strName, FunctionArguments );
274283
NewArguments.PushArguments( FunctionArguments );
275284

276285
CallHook( strName, m_PostFunctionHookList, NewArguments, bNameMustBeExplicitlyAllowed );
@@ -398,6 +407,28 @@ bool CDebugHookManager::MustNameBeExplicitlyAllowed( const SString& strName )
398407
}
399408

400409

410+
///////////////////////////////////////////////////////////////
411+
//
412+
// CDebugHookManager::MaybeMaskArgumentValues
413+
//
414+
// Mask security sensitive argument values
415+
//
416+
///////////////////////////////////////////////////////////////
417+
void CDebugHookManager::MaybeMaskArgumentValues( const SString& strFunctionName, CLuaArguments& FunctionArguments )
418+
{
419+
auto* pArgIndexList = MapFind( m_MaskArgumentsMap, strFunctionName );
420+
if ( pArgIndexList )
421+
{
422+
for ( uint uiIndex : *pArgIndexList )
423+
{
424+
CLuaArgument* pArgument = FunctionArguments[uiIndex];
425+
if ( pArgument )
426+
pArgument->ReadString( "***" );
427+
}
428+
}
429+
}
430+
431+
401432
///////////////////////////////////////////////////////////////
402433
//
403434
// CDebugHookManager::CallHook

Shared/mods/deathmatch/logic/CDebugHookManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ class CDebugHookManager
5050
bool CallHook ( const char* szName, const std::vector < SDebugHookCallInfo >& eventHookList, const CLuaArguments& Arguments, bool bNameMustBeExplicitlyAllowed = false );
5151
bool IsNameAllowed ( const char* szName, const std::vector < SDebugHookCallInfo >& eventHookList, bool bNameMustBeExplicitlyAllowed = false );
5252
bool MustNameBeExplicitlyAllowed ( const SString& strName );
53+
void MaybeMaskArgumentValues ( const SString& strFunctionName, CLuaArguments& FunctionArguments );
5354

5455
uint m_uiPostFunctionOverride;
5556
std::vector < SDebugHookCallInfo > m_PreEventHookList;
5657
std::vector < SDebugHookCallInfo > m_PostEventHookList;
5758
std::vector < SDebugHookCallInfo > m_PreFunctionHookList;
5859
std::vector < SDebugHookCallInfo > m_PostFunctionHookList;
60+
std::map< SString, std::vector<uint> > m_MaskArgumentsMap;
5961
};

0 commit comments

Comments
 (0)