1515import os
1616import sys
1717import time
18+ import warnings
1819from abc import ABC , abstractmethod
1920from collections .abc import Sequence
2021from copy import copy
3435logger = get_logger (module_name = __name__ )
3536
3637
38+ def _warn_logging_file_execution (logging_file : str ) -> None :
39+ """
40+ Warn that ``logging_file`` is about to be executed by `logging.config.fileConfig`.
41+
42+ Called immediately before every `fileConfig` invocation in this module, so the warning is only
43+ raised when the file is really executed -- not when it is missing or logging is disabled.
44+ """
45+ warnings .warn (
46+ f"applying logging config { logging_file } : `logging.config.fileConfig` passes the `class=` and "
47+ "`args=` fields of the INI's handler and formatter sections to Python `eval()`, so this file "
48+ "runs as code. A bundle ships its own `configs/logging.conf` and it is applied by default, "
49+ "before any of the bundle's config is parsed. Only proceed if this file is from a source you "
50+ "trust (see https://github.com/Project-MONAI/MONAI/security/advisories/GHSA-wvpx-5qmp-46g3)." ,
51+ stacklevel = 3 ,
52+ )
53+
54+
3755class BundleWorkflow (ABC ):
3856 """
3957 Base class for the workflow specification in bundle, it can be a training, evaluation or inference workflow.
@@ -55,6 +73,10 @@ class BundleWorkflow(ABC):
5573 meta_file: filepath of the metadata file, if this is a list of file paths, their contents will be merged in order.
5674 logging_file: config file for `logging` module in the program. for more details:
5775 https://docs.python.org/3/library/logging.config.html#logging.config.fileConfig.
76+ Security note: `fileConfig` passes the INI's `class=` and `args=` fields to Python
77+ `eval()`, so this file runs as code and applying it raises a warning -- once per call
78+ site, as Python's default warning filter suppresses repeats
79+ (see https://github.com/Project-MONAI/MONAI/security/advisories/GHSA-wvpx-5qmp-46g3).
5880
5981 """
6082
@@ -72,6 +94,7 @@ def __init__(
7294 if not os .path .isfile (logging_file ):
7395 raise FileNotFoundError (f"Cannot find the logging config file: { logging_file } ." )
7496 logger .info (f"Setting logging properties based on config: { logging_file } ." )
97+ _warn_logging_file_execution (logging_file )
7598 fileConfig (logging_file , disable_existing_loggers = False )
7699
77100 if meta_file is not None :
@@ -273,6 +296,10 @@ class PythonicWorkflow(BundleWorkflow):
273296 meta_file: filepath of the metadata file, if this is a list of file paths, their contents will be merged in order.
274297 logging_file: config file for `logging` module in the program. for more details:
275298 https://docs.python.org/3/library/logging.config.html#logging.config.fileConfig.
299+ Security note: `fileConfig` passes the INI's `class=` and `args=` fields to Python
300+ `eval()`, so this file runs as code and applying it raises a warning -- once per call
301+ site, as Python's default warning filter suppresses repeats
302+ (see https://github.com/Project-MONAI/MONAI/security/advisories/GHSA-wvpx-5qmp-46g3).
276303
277304 """
278305
@@ -375,6 +402,10 @@ class ConfigWorkflow(BundleWorkflow):
375402 https://docs.python.org/3/library/logging.config.html#logging.config.fileConfig.
376403 If None, default to "configs/logging.conf", which is commonly used for bundles in MONAI model zoo.
377404 If False, the logging logic for the bundle will not be modified.
405+ Security note: `fileConfig` passes the INI's `class=` and `args=` fields to Python
406+ `eval()`, so this file runs as code and applying it raises a warning -- once per call
407+ site, as Python's default warning filter suppresses repeats
408+ (see https://github.com/Project-MONAI/MONAI/security/advisories/GHSA-wvpx-5qmp-46g3).
378409 init_id: ID name of the expected config expression to initialize before running, default to "initialize".
379410 allow a config to have no `initialize` logic and the ID.
380411 run_id: ID name of the expected config expression to run, default to "run".
@@ -444,6 +475,7 @@ def __init__(
444475 else :
445476 raise FileNotFoundError (f"Cannot find the logging config file: { logging_file } ." )
446477 else :
478+ _warn_logging_file_execution (str (logging_file ))
447479 fileConfig (str (logging_file ), disable_existing_loggers = False )
448480 logger .info (f"Setting logging properties based on config: { logging_file } ." )
449481
0 commit comments