Git hooks
The cheapest place to stop malicious code is before it enters your history. Hooks scan only the files you're committing, so they finish in seconds.
With the pre-commit framework (recommended)
Add this to .pre-commit-config.yaml in your repository:
repos:
- repo: https://github.com/benzid-wael/malware-detector
rev: v0.1.0 # pin to a release tag
hooks:
- id: malware-detectorThen install the hook:
pre-commit installFrom now on, every git commit scans the staged JavaScript, TypeScript, Python and PHP files. If anything at or above MEDIUM is found, the commit is blocked and the report is printed.
Pass extra flags with args, for example to block only on strong signals:
- id: malware-detector
args: [--fail-on, HIGH]TIP
pre-commit builds its own environment for the hook. Make sure a Python 3.10–3.13 interpreter is available, for example with default_language_version: { python: python3.13 } in your config.
With a plain git hook
If you don't use the pre-commit framework, use a two-line hook. It needs malware-detector on your PATH; see Get started.
# .git/hooks/pre-commit (chmod +x)
#!/bin/sh
exec malware-detector scan --stagedTo also scan before pushing, covering everything that changed since HEAD, including untracked files:
# .git/hooks/pre-push (chmod +x)
#!/bin/sh
exec malware-detector scan --changedWith Husky (JavaScript projects)
# .husky/pre-commit
malware-detector scan --stagedWhen the hook blocks you
- Read the finding. Add
--explain(run the command by hand) to see the matched line. - If it's real, don't commit it. Remove the code and find out where it came from.
- If it's a false positive, add a narrow entry with a reason to
.malware-detector-ignore.json, and commit that file too.
Avoid git commit --no-verify. It skips the scan for everyone who follows that habit.