Skip to content

Replace Safety with Bandit #1113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ jobs:
version: ['3.9', '3.10', '3.11', '3.12', '3.13']
include:
- version: '3.9'
tox-env: py39,py39-mypy,py39-lint,safety
tox-env: py39,py39-mypy,py39-lint,bandit
- version: '3.10'
tox-env: py310,py310-mypy,py310-lint,safety
tox-env: py310,py310-mypy,py310-lint,bandit
- version: '3.11'
tox-env: py311,py311-mypy,py311-lint,safety
tox-env: py311,py311-mypy,py311-lint,bandit
- version: '3.12'
tox-env: py312,py312-mypy,py312-lint,format,safety
tox-env: py312,py312-mypy,py312-lint,format,bandit
- version: '3.13'
tox-env: py313,py313-mypy,py313-lint,safety
tox-env: py313,py313-mypy,py313-lint,bandit
- os: windows-latest
version: '3.13'
tox-env: py313,safety
tox-env: py313,bandit
- os: macos-latest
version: '3.13'
tox-env: py313,safety
tox-env: py313,bandit
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ format:
.PHONY: check
check:
@rm -f .coverage*
@TOX_SKIP_ENV='pypy3|safety|coverage' poetry run tox run-parallel -p auto
@TOX_SKIP_ENV='pypy3|bandit|coverage' poetry run tox run-parallel -p auto


.PHONY: lint
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ basilisp_test_runner = "basilisp.contrib.pytest.testrunner"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.bandit]
skips = ["B101"]

[tool.black]
line-length = 88
target-version = ["py39"]
Expand Down
2 changes: 1 addition & 1 deletion src/basilisp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def run_script():
if rest := sys.argv[2:]:
args.append("--")
args.extend(rest)
os.execvp("basilisp", args)
os.execvp("basilisp", args) # nosec B606, B607


def invoke_cli(args: Optional[Sequence[str]] = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/basilisp/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _get_basilisp_bytecode(
logger.debug(message)
raise ImportError(message, **exc_details)

return marshal.loads(cache_data[12:])
return marshal.loads(cache_data[12:]) # nosec 6302


def _cache_from_source(path: str) -> str:
Expand Down
6 changes: 3 additions & 3 deletions src/basilisp/lang/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def compile_and_exec_form(
bytecode = compile(ast_module, ctx.filename, "exec")
if collect_bytecode:
collect_bytecode(bytecode)
exec(bytecode, ns.module.__dict__) # pylint: disable=exec-used
exec(bytecode, ns.module.__dict__) # pylint: disable=exec-used # nosec 6102
try:
last = getattr(ns.module, final_wrapped_name)()
finally:
Expand Down Expand Up @@ -222,7 +222,7 @@ def _incremental_compile_module(
bytecode = compile(module, source_filename, "exec")
if collect_bytecode:
collect_bytecode(bytecode)
exec(bytecode, ns.module.__dict__) # pylint: disable=exec-used
exec(bytecode, ns.module.__dict__) # pylint: disable=exec-used # nosec 6102


def _bootstrap_module(
Expand Down Expand Up @@ -284,7 +284,7 @@ def compile_bytecode(
and then proceeds to compile a collection of bytecodes into the module."""
_bootstrap_module(gctx, optimizer, ns)
for bytecode in code:
exec(bytecode, ns.module.__dict__) # pylint: disable=exec-used
exec(bytecode, ns.module.__dict__) # pylint: disable=exec-used # nosec 6102


_LOAD_SYM = sym.symbol("load", ns=runtime.CORE_NS)
Expand Down
2 changes: 1 addition & 1 deletion src/basilisp/lang/compiler/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,7 +2291,7 @@ def _import_hash(s: str) -> str:
the new session can find objects generated by the session which generated the
cache file. Since we are not concerned with being able to round-trip this data,
destructive modifications are not an issue."""
digest = hashlib.md5(s.encode()).digest()
digest = hashlib.md5(s.encode()).digest() # nosec B324
return base64.b64encode(digest).decode().translate(_IMPORT_HASH_TRANSLATE_TABLE)[:6]


Expand Down
10 changes: 4 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py39,py310,py311,py312,py313,pypy3,coverage,py{39,310,311,312,313}-mypy,py{39,310,311,312,313}-lint,format,safety
envlist = py39,py310,py311,py312,py313,pypy3,coverage,py{39,310,311,312,313}-mypy,py{39,310,311,312,313}-lint,format,bandit
labels =
test = py39,py310,py311,py312,py313

Expand Down Expand Up @@ -58,10 +58,8 @@ commands =
pylint src/
ruff check src/

[testenv:safety]
[testenv:bandit]
deps =
safety
# work around 3.13 issue to avoid building an earlier version of pydantic-core on macos
pydantic-core>=2.25.0
bandit[toml]
commands =
safety check -i 40291 -i 67599 -i 70612
bandit -c {toxinidir}/pyproject.toml -r {toxinidir}/src/basilisp