This report outlines the caveats, issues, and security implications of the new auto-discovery features in script2stlite.
The auto-discovery mechanism (script2stlite/discovery.py) has been simplified to:
Bundle all files in the provided directory, excluding standard system/IDE directories (e.g., .git, __pycache__, venv, node_modules).
This replaces the previous AST-based static analysis, ensuring that all functional dependencies (dynamic imports, f-string assets, etc.) are included, provided they exist in the directory.
Issue: Since all files in the directory are bundled, any sensitive file present (e.g., .env, secrets.txt, keys/) will be included in the public HTML bundle.
Mitigation: Users must adhere to the Clean Directory Principle:
- The directory provided to
script2stliteshould contain only the application files intended for distribution. - Environment files (like
.env) should generally be kept out of the target directory or added to a manual exclusion list if implemented in the future. (Note:.envis currently in the default ignore list).
Issue: Local files with names matching standard library modules (e.g., json.py, html.py) will be bundled.
Impact:
- In the Pyodide environment,
import jsonwill import the localjson.pyinstead of the standard libraryjsonmodule, potentially breaking the application. - This is standard Python behavior, but more likely to occur if users include random scripts in the directory.
The following issues identified in previous audits are resolved by the "include all" strategy:
- Dynamic Imports:
importlib.import_module("foo")now works becausefoo.pyis included if present. - Constructed File Paths:
f"data/{name}.csv"now works because all files indata/are included. - Wildcard Imports:
from pkg import *now works because the entire package directory is included. - False Negatives: No more missing files due to parser limitations.
The following files and directories are excluded by default to keep bundles clean:
Directories:
.git__pycache__venv,.venv,env.mypy_cache,.pytest_cachedist,build.idea,.vscodenode_modules
Files:
.DS_Store.gitignore.env
A test suite tests/test_audit_scenarios.py verifies these behaviors.
| Scenario | Behavior | Status |
|---|---|---|
| Static Import | import foo -> bundles foo.py |
✅ Working |
| Dynamic Import | importlib.import_module('foo') -> bundles foo.py |
✅ Working |
| Dynamic Asset | open(f"{file}.csv") -> bundles data.csv |
✅ Working |
| Unused Files | unused.txt -> bundles unused.txt |
✅ Working (Intended) |
| Secrets | .env present in dir -> ignored by default |
✅ Working |
| Ignored Dirs | .git folder -> ignored |
✅ Working |