Skip to main content

SKY-D347 · Security in code

Logging configuration accepted over a socket

MediumCWE-306

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

app/logging_setup.py · PythonReported on line 9
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

app/logging_setup.py · Python
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

  1. Runs with --danger on Python files. Resolves import aliases, so logging.config.listen(...), from logging import config followed by config.listen(...), and from logging.config import listen all count.
  2. 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.

app/logging_setup.py · Python · the fix, against the flagged file
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), where check rejects 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.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.