SKY-D347 · Security in code
Logging configuration accepted over a socket
Python's logging.config.listen() starts a thread that waits on a local TCP port (9030 by default) and applies any logging configuration sent to it. SKY-D347 reports every call to it.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
- Catalog name
- Unsafe logging config listener
Why it matters
A logging configuration can name classes and functions to create, so whoever sends one can run code inside your process. The listener binds to localhost and asks for no password: on a shared server, or in a pod with other containers, any local user or process can connect and take over the application.
What Skylos flags
import loggingimport logging.config log = logging.getLogger("orders") def start_logging(): logging.config.fileConfig("logging.ini") listener = logging.config.listen(9030) listener.daemon = True listener.start() log.info("logging configured; send changes to port 9030")What Skylos leaves alone
import loggingimport logging.config import yaml log = logging.getLogger("orders") def start_logging(): with open("logging.yaml", encoding="utf-8") as handle: logging.config.dictConfig(yaml.safe_load(handle)) log.info("logging configured")Why Skylos leaves it alone
The configuration comes from a file the deployment owns and is read once at start-up; nothing listens on a port. dictConfig() and fileConfig() are not reported, only listen().
How Skylos decides
- Runs with
--dangeron Python files. Resolves import aliases, sologging.config.listen(...),from logging import configfollowed byconfig.listen(...), andfrom logging.config import listenall count. - Reports MEDIUM on every such call. The arguments are not read: a call that passes
verify=is reported too, and test files are not skipped.
How to fix it
Do not accept configuration over a socket. Keep it in a file the deployment controls and reload it when the process gets a signal, or restart the service to apply changes.
import loggingimport logging.configAdded: import signal log = logging.getLogger("orders") Added: def _reload(signum, frame):Added: logging.config.fileConfig("logging.ini", disable_existing_loggers=False)Added: log.info("logging reloaded")Added: Added: def start_logging(): logging.config.fileConfig("logging.ini")Removed: listener = logging.config.listen(9030)Removed: listener.daemon = TrueRemoved: listener.start()Removed: log.info("logging configured; send changes to port 9030")Added: signal.signal(signal.SIGHUP, _reload)Added: log.info("logging configured; send SIGHUP to reload")When it can be wrong
- Python's documentation recommends
listen(port, verify=check), wherecheckrejects any configuration without a valid signature. Skylos still reports that call; mark it as reviewed. - A single-user machine or a container with no other process has no one else to connect, but the call is reported all the same.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark a call that verifies what it receives, and say how.
Python logging.config.listen(9030, verify=check_hmac) # skylos: ignore[SKY-D347] signed[tool.skylos] ignore = ["SKY-D347"]turns the rule off for the whole project.