diff mbox series

[bitbake-devel,1/2] exceptions: Add option to hide frame arguments in exceptions

Message ID 20241126221829.2825101-2-JPEWhacker@gmail.com
State New
Headers show
Series Fix hash server passwords leaking in logs | expand

Commit Message

Joshua Watt Nov. 26, 2024, 10:16 p.m. UTC
The exception code in bitbake prints out the arguments to functions
calls, and while this is very useful, it means that if there are secret
credentials in arguments (like the password for bitbake hashserver
client), they will be shown in the logs and potentially leaked.

To prevent this, add code that checks for the local variable
HIDE_FRAME_ARGS in the function. If present and set to True, the
exception code will not print the value of any of the function
arguments.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 bitbake/lib/bb/exceptions.py | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/bitbake/lib/bb/exceptions.py b/bitbake/lib/bb/exceptions.py
index 60643bd6421..931140da0c6 100644
--- a/bitbake/lib/bb/exceptions.py
+++ b/bitbake/lib/bb/exceptions.py
@@ -36,26 +36,24 @@  class TracebackEntry(namedtuple.abc):
 
 def _get_frame_args(frame):
     """Get the formatted arguments and class (if available) for a frame"""
-    arginfo = inspect.getargvalues(frame)
+    args, varargs, keywords, local = inspect.getargvalues(frame)
+    if not args:
+        return '', None
 
-    if not arginfo.args:
-            return '', None
-
-    firstarg = arginfo.args[0]
+    firstarg = args[0]
     if firstarg == 'self':
-        self = arginfo.locals['self']
+        self = local['self']
         cls = self.__class__.__name__
 
-        arginfo.args.pop(0)
-        try:
-            del arginfo.locals['self']
-        except TypeError:
-            # FIXME - python 3.13 FrameLocalsProxy can't be modified
-            pass
+        args.pop(0)
+        del local['self']
     else:
         cls = None
 
-    formatted = inspect.formatargvalues(*arginfo)
+    if local.get("HIDE_FRAME_ARGS", False):
+        return '(HIDDEN)', cls
+
+    formatted = inspect.formatargvalues(args, varargs, keywords, local)
     return formatted, cls
 
 def extract_traceback(tb, context=1):