-
-
Notifications
You must be signed in to change notification settings - Fork 418
Description
Describe the bug
The __init__ of class grass.app.runtime.RuntimePaths uses a dangerous default value, and it is already flagged by Pylint W0102. They also leak in the generated docs.
grass/python/grass/app/runtime.py
Lines 28 to 36 in 84ab511
| class RuntimePaths: | |
| """Get runtime paths to resources and basic GRASS build properties | |
| The resource paths are also set as environmental variables. | |
| """ | |
| def __init__(self, env=os.environ): | |
| self.env = env | |
This mutable default value behavior was the first real Python problem that bit me years and years ago, and made me interested on how Python works. It is easy to get affected and not understand why things don't work.
That pylint warning is not enforced yet, as we have tons of places where we use an empty list for example. See the Pylint W0102 docs to understand the effect and the kind of fix needed.
The dangerous part here for us is that the contents of the env vars are reproduced in the rendered html docs, and change for each run.
We were lucky the env var GITHUB_TOKEN or other more sensitive info didn't show up in the published docs, as shown in the screenshots below.
There's also the problem of systematically have differences in the content, even if unchanged.
To reproduce
- Generate sphinx docs or download the mkdocs-site artifact of any documentation.yml workflow.
- Go to the docs for grass.app.runtime.RuntimePaths, or the published https://grass.osgeo.org/grass-devel/manuals/libpython/grass.app.html#grass.app.runtime.RuntimePaths
- See leaked env vars in docstring
Expected behavior
The environment vars are not leaked systematically
Screenshots
Always different values:
System description
- Operating System: Linux Ubuntu 22.04 on GitHub actions CI, in the documentation.yml workflow
- GRASS GIS version: 8.5.0dev, at least in the main branch from 76bbc71, but probably ever since build: refactor grass.py in preparation for FHS #5933 two weeks ago.