pushward 0.2.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pushward-0.2.6/LICENSE +21 -0
- pushward-0.2.6/PKG-INFO +161 -0
- pushward-0.2.6/README.md +127 -0
- pushward-0.2.6/pushward/__init__.py +3 -0
- pushward-0.2.6/pushward/__main__.py +6 -0
- pushward-0.2.6/pushward/checks/__init__.py +0 -0
- pushward-0.2.6/pushward/checks/dni_pattern.py +82 -0
- pushward-0.2.6/pushward/checks/private_ips.py +52 -0
- pushward-0.2.6/pushward/checks/secrets.py +114 -0
- pushward-0.2.6/pushward/checks/sensitive_filenames.py +45 -0
- pushward-0.2.6/pushward/checks/watchlist.py +65 -0
- pushward-0.2.6/pushward/cli.py +174 -0
- pushward-0.2.6/pushward/hook.py +33 -0
- pushward-0.2.6/pushward/ignorefile.py +27 -0
- pushward-0.2.6/pushward/plugin.py +34 -0
- pushward-0.2.6/pushward/report.py +63 -0
- pushward-0.2.6/pushward/runner.py +47 -0
- pushward-0.2.6/pushward/scanner.py +143 -0
- pushward-0.2.6/pushward/watchlist_store.py +83 -0
- pushward-0.2.6/pushward.egg-info/PKG-INFO +161 -0
- pushward-0.2.6/pushward.egg-info/SOURCES.txt +39 -0
- pushward-0.2.6/pushward.egg-info/dependency_links.txt +1 -0
- pushward-0.2.6/pushward.egg-info/entry_points.txt +9 -0
- pushward-0.2.6/pushward.egg-info/requires.txt +6 -0
- pushward-0.2.6/pushward.egg-info/top_level.txt +1 -0
- pushward-0.2.6/pyproject.toml +68 -0
- pushward-0.2.6/setup.cfg +4 -0
- pushward-0.2.6/tests/test_cli.py +159 -0
- pushward-0.2.6/tests/test_dni_pattern.py +70 -0
- pushward-0.2.6/tests/test_hook.py +41 -0
- pushward-0.2.6/tests/test_ignorefile.py +24 -0
- pushward-0.2.6/tests/test_plugin.py +19 -0
- pushward-0.2.6/tests/test_private_ips.py +47 -0
- pushward-0.2.6/tests/test_report.py +41 -0
- pushward-0.2.6/tests/test_runner.py +44 -0
- pushward-0.2.6/tests/test_scanner.py +90 -0
- pushward-0.2.6/tests/test_secrets.py +159 -0
- pushward-0.2.6/tests/test_sensitive_filenames.py +43 -0
- pushward-0.2.6/tests/test_version.py +11 -0
- pushward-0.2.6/tests/test_watchlist.py +50 -0
- pushward-0.2.6/tests/test_watchlist_store.py +102 -0
pushward-0.2.6/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 José Luis Segura Yuste
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pushward-0.2.6/PKG-INFO
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pushward
|
|
3
|
+
Version: 0.2.6
|
|
4
|
+
Summary: Escáner pre-commit/pre-push de secretos y datos reales (IPs, nombres, entidades) antes de que lleguen a un repo — arquitectura de plugins.
|
|
5
|
+
Author: José Luis Segura Yuste
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/jl-segurayuste/pushward
|
|
8
|
+
Project-URL: Source, https://github.com/jl-segurayuste/pushward
|
|
9
|
+
Project-URL: Issues, https://github.com/jl-segurayuste/pushward/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/jl-segurayuste/pushward/releases
|
|
11
|
+
Keywords: git-hooks,security
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Natural Language :: Spanish
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
23
|
+
Classifier: Topic :: Security
|
|
24
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: pydantic>=2.6
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
31
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
32
|
+
Requires-Dist: ruff==0.17.6; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# pushward
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/pushward/)
|
|
38
|
+
[](https://github.com/jl-segurayuste/pushward/actions/workflows/ci.yml)
|
|
39
|
+
[](https://github.com/jl-segurayuste/pushward/blob/main/pyproject.toml)
|
|
40
|
+
[](https://github.com/jl-segurayuste/pushward/blob/main/LICENSE)
|
|
41
|
+
|
|
42
|
+
Escáner de secretos y datos reales antes de que lleguen a un repositorio —
|
|
43
|
+
pensado para engancharse como hook `pre-push`, no solo como auditoría puntual.
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
$ pushward scan .
|
|
47
|
+
|
|
48
|
+
pushward — /ruta/al/repo
|
|
49
|
+
|
|
50
|
+
── secrets ──────────────────────────────
|
|
51
|
+
40 fichero(s) analizados, 1 hallazgo(s).
|
|
52
|
+
[HIGH ] Posible secreto: Clave privada (PEM) (deploy/id_rsa:1)
|
|
53
|
+
Revisar y revocar si es real antes de publicar.
|
|
54
|
+
|
|
55
|
+
── watchlist ────────────────────────────
|
|
56
|
+
3 entrada(s) en la watchlist, 40 fichero(s) analizados, 1 hallazgo(s).
|
|
57
|
+
[HIGH ] Entrada de watchlist encontrada: 'AcmeCorp' (docs/notas.md:12)
|
|
58
|
+
|
|
59
|
+
Total: 2 hallazgo(s) — 2 high
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Así se ve
|
|
63
|
+
|
|
64
|
+

|
|
65
|
+
|
|
66
|
+
<sub>Ejecución real sobre un repo de ejemplo con un DNI, una clave de AWS, una IP interna, un nombre de la watchlist y un PDF de nóminas (todos los datos son ficticios).</sub>
|
|
67
|
+
|
|
68
|
+
## Por qué existe
|
|
69
|
+
|
|
70
|
+
Los escáneres de secretos habituales (git-secrets, gitleaks...) casan patrones:
|
|
71
|
+
claves con forma de clave, tokens con forma de token. Pero la fuga más
|
|
72
|
+
frecuente en la práctica no tiene "forma" reconocible por regex — es una IP
|
|
73
|
+
interna real, el nombre de un cliente, el de un empleado, o un DNI de verdad
|
|
74
|
+
colado como "ejemplo". Ningún escáner por patrones puede distinguir eso de un
|
|
75
|
+
valor inventado, porque no sabe qué es real. `pushward` sí puede, porque tú se
|
|
76
|
+
lo dices una vez (la `watchlist`) y lo comprueba en todos tus repos, para
|
|
77
|
+
siempre.
|
|
78
|
+
|
|
79
|
+
## Instalación
|
|
80
|
+
|
|
81
|
+
Todavía no está en PyPI:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pipx install pushward # recomendado para herramientas de línea de comandos
|
|
85
|
+
# o bien
|
|
86
|
+
pip install pushward
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Uso
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
pushward scan . # informe en consola
|
|
93
|
+
pushward scan . --staged # solo lo que hay en stage (usado por el hook)
|
|
94
|
+
pushward scan . --json
|
|
95
|
+
pushward scan . --fail-on high # código de salida 1 si hay algo "high"
|
|
96
|
+
# código 2 si algún check no se pudo ejecutar (análisis incompleto)
|
|
97
|
+
pushward list-checks
|
|
98
|
+
|
|
99
|
+
pushward install-hook . # instala un hook pre-push en este repo
|
|
100
|
+
pushward uninstall-hook .
|
|
101
|
+
|
|
102
|
+
pushward watchlist add "Nombre Real" # nunca se commitea: vive en ~/.config/pushward/
|
|
103
|
+
pushward watchlist list
|
|
104
|
+
pushward watchlist remove "Nombre Real"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
El hook `pre-push` revisa **el contenido de cada commit que se sube**, no el árbol de trabajo:
|
|
108
|
+
un secreto añadido en un commit y quitado en el siguiente también se ve (viaja en el historial).
|
|
109
|
+
Bloquea el push si hay algo `high`, si un check falla al ejecutarse o si no puede saber qué se va
|
|
110
|
+
a subir (por ejemplo, un `push --force` sobre un remoto con commits que no tienes: entonces revisa
|
|
111
|
+
todo lo que no esté ya en ningún remoto conocido).
|
|
112
|
+
|
|
113
|
+
## Checks incluidos
|
|
114
|
+
|
|
115
|
+
| Check | Qué detecta |
|
|
116
|
+
|---|---|
|
|
117
|
+
| `secrets` | Claves privadas (también cifradas y PGP), tokens AWS/GitHub/Slack/OpenAI/Anthropic, JWT, asignaciones de credenciales en claro (Python, YAML, `.env`, `export`, JS, PowerShell, JSON) |
|
|
118
|
+
| `private_ips` | IPs de rangos privados (10.x, 172.16-31.x, 192.168.x) |
|
|
119
|
+
| `watchlist` | Nombres/empresas/dominios reales que tú has marcado como "nunca en un repo" |
|
|
120
|
+
| `dni_pattern` | DNI/NIE español con dígito de control válido (no marca placeholders tipo `12345678A`) |
|
|
121
|
+
| `sensitive_filenames` | Nombres de fichero (PDF/DOCX/XLSX) que sugieren contenido personal, sin abrir el contenido |
|
|
122
|
+
|
|
123
|
+
Ninguno ejecuta el código del repo analizado. Cada check es un plugin
|
|
124
|
+
independiente (`importlib.metadata.entry_points`, grupo `pushward.checks`) —
|
|
125
|
+
añadir uno nuevo no toca el núcleo.
|
|
126
|
+
|
|
127
|
+
## La watchlist
|
|
128
|
+
|
|
129
|
+
Vive fuera de cualquier repo, en `~/.config/pushward/watchlist.txt` —
|
|
130
|
+
justo porque el propio fichero contendría los nombres que quieres proteger,
|
|
131
|
+
así que no tiene sentido que viva dentro de un repo que podrías publicar.
|
|
132
|
+
Casa variantes de mayúsculas y separador (`Ruben.Blanco` == `ruben_blanco` ==
|
|
133
|
+
`RubenBlanco`) y sin tener en cuenta las tildes (`Laura Gómez` == `laura.gomez`),
|
|
134
|
+
con límites de palabra para no marcar falsos positivos como "AcmeCorp" dentro
|
|
135
|
+
de "consumo".
|
|
136
|
+
|
|
137
|
+
## Excluir ficheros del escaneo (.pushwardignore)
|
|
138
|
+
|
|
139
|
+
Una herramienta de seguridad necesariamente tiene, en sus propios tests,
|
|
140
|
+
fixtures que *parecen* secretos/DNI reales a propósito (para poder probar
|
|
141
|
+
que los detecta). Un `.pushwardignore` en la raíz del repo (una ruta o
|
|
142
|
+
patrón por línea, comentarios con `#`) excluye esos ficheros del escaneo
|
|
143
|
+
por completo:
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
tests/test_secrets.py
|
|
147
|
+
tests/test_dni_pattern.py
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Úsalo para excepciones concretas y documentadas, no como atajo para ignorar
|
|
151
|
+
avisos reales.
|
|
152
|
+
|
|
153
|
+
## Desarrollo
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
pip install -e ".[dev]"
|
|
157
|
+
ruff check .
|
|
158
|
+
pytest
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Ver [CONTRIBUTING.md](CONTRIBUTING.md) para añadir un check nuevo.
|
pushward-0.2.6/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# pushward
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/pushward/)
|
|
4
|
+
[](https://github.com/jl-segurayuste/pushward/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/jl-segurayuste/pushward/blob/main/pyproject.toml)
|
|
6
|
+
[](https://github.com/jl-segurayuste/pushward/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Escáner de secretos y datos reales antes de que lleguen a un repositorio —
|
|
9
|
+
pensado para engancharse como hook `pre-push`, no solo como auditoría puntual.
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
$ pushward scan .
|
|
13
|
+
|
|
14
|
+
pushward — /ruta/al/repo
|
|
15
|
+
|
|
16
|
+
── secrets ──────────────────────────────
|
|
17
|
+
40 fichero(s) analizados, 1 hallazgo(s).
|
|
18
|
+
[HIGH ] Posible secreto: Clave privada (PEM) (deploy/id_rsa:1)
|
|
19
|
+
Revisar y revocar si es real antes de publicar.
|
|
20
|
+
|
|
21
|
+
── watchlist ────────────────────────────
|
|
22
|
+
3 entrada(s) en la watchlist, 40 fichero(s) analizados, 1 hallazgo(s).
|
|
23
|
+
[HIGH ] Entrada de watchlist encontrada: 'AcmeCorp' (docs/notas.md:12)
|
|
24
|
+
|
|
25
|
+
Total: 2 hallazgo(s) — 2 high
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Así se ve
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
<sub>Ejecución real sobre un repo de ejemplo con un DNI, una clave de AWS, una IP interna, un nombre de la watchlist y un PDF de nóminas (todos los datos son ficticios).</sub>
|
|
33
|
+
|
|
34
|
+
## Por qué existe
|
|
35
|
+
|
|
36
|
+
Los escáneres de secretos habituales (git-secrets, gitleaks...) casan patrones:
|
|
37
|
+
claves con forma de clave, tokens con forma de token. Pero la fuga más
|
|
38
|
+
frecuente en la práctica no tiene "forma" reconocible por regex — es una IP
|
|
39
|
+
interna real, el nombre de un cliente, el de un empleado, o un DNI de verdad
|
|
40
|
+
colado como "ejemplo". Ningún escáner por patrones puede distinguir eso de un
|
|
41
|
+
valor inventado, porque no sabe qué es real. `pushward` sí puede, porque tú se
|
|
42
|
+
lo dices una vez (la `watchlist`) y lo comprueba en todos tus repos, para
|
|
43
|
+
siempre.
|
|
44
|
+
|
|
45
|
+
## Instalación
|
|
46
|
+
|
|
47
|
+
Todavía no está en PyPI:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pipx install pushward # recomendado para herramientas de línea de comandos
|
|
51
|
+
# o bien
|
|
52
|
+
pip install pushward
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Uso
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pushward scan . # informe en consola
|
|
59
|
+
pushward scan . --staged # solo lo que hay en stage (usado por el hook)
|
|
60
|
+
pushward scan . --json
|
|
61
|
+
pushward scan . --fail-on high # código de salida 1 si hay algo "high"
|
|
62
|
+
# código 2 si algún check no se pudo ejecutar (análisis incompleto)
|
|
63
|
+
pushward list-checks
|
|
64
|
+
|
|
65
|
+
pushward install-hook . # instala un hook pre-push en este repo
|
|
66
|
+
pushward uninstall-hook .
|
|
67
|
+
|
|
68
|
+
pushward watchlist add "Nombre Real" # nunca se commitea: vive en ~/.config/pushward/
|
|
69
|
+
pushward watchlist list
|
|
70
|
+
pushward watchlist remove "Nombre Real"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
El hook `pre-push` revisa **el contenido de cada commit que se sube**, no el árbol de trabajo:
|
|
74
|
+
un secreto añadido en un commit y quitado en el siguiente también se ve (viaja en el historial).
|
|
75
|
+
Bloquea el push si hay algo `high`, si un check falla al ejecutarse o si no puede saber qué se va
|
|
76
|
+
a subir (por ejemplo, un `push --force` sobre un remoto con commits que no tienes: entonces revisa
|
|
77
|
+
todo lo que no esté ya en ningún remoto conocido).
|
|
78
|
+
|
|
79
|
+
## Checks incluidos
|
|
80
|
+
|
|
81
|
+
| Check | Qué detecta |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `secrets` | Claves privadas (también cifradas y PGP), tokens AWS/GitHub/Slack/OpenAI/Anthropic, JWT, asignaciones de credenciales en claro (Python, YAML, `.env`, `export`, JS, PowerShell, JSON) |
|
|
84
|
+
| `private_ips` | IPs de rangos privados (10.x, 172.16-31.x, 192.168.x) |
|
|
85
|
+
| `watchlist` | Nombres/empresas/dominios reales que tú has marcado como "nunca en un repo" |
|
|
86
|
+
| `dni_pattern` | DNI/NIE español con dígito de control válido (no marca placeholders tipo `12345678A`) |
|
|
87
|
+
| `sensitive_filenames` | Nombres de fichero (PDF/DOCX/XLSX) que sugieren contenido personal, sin abrir el contenido |
|
|
88
|
+
|
|
89
|
+
Ninguno ejecuta el código del repo analizado. Cada check es un plugin
|
|
90
|
+
independiente (`importlib.metadata.entry_points`, grupo `pushward.checks`) —
|
|
91
|
+
añadir uno nuevo no toca el núcleo.
|
|
92
|
+
|
|
93
|
+
## La watchlist
|
|
94
|
+
|
|
95
|
+
Vive fuera de cualquier repo, en `~/.config/pushward/watchlist.txt` —
|
|
96
|
+
justo porque el propio fichero contendría los nombres que quieres proteger,
|
|
97
|
+
así que no tiene sentido que viva dentro de un repo que podrías publicar.
|
|
98
|
+
Casa variantes de mayúsculas y separador (`Ruben.Blanco` == `ruben_blanco` ==
|
|
99
|
+
`RubenBlanco`) y sin tener en cuenta las tildes (`Laura Gómez` == `laura.gomez`),
|
|
100
|
+
con límites de palabra para no marcar falsos positivos como "AcmeCorp" dentro
|
|
101
|
+
de "consumo".
|
|
102
|
+
|
|
103
|
+
## Excluir ficheros del escaneo (.pushwardignore)
|
|
104
|
+
|
|
105
|
+
Una herramienta de seguridad necesariamente tiene, en sus propios tests,
|
|
106
|
+
fixtures que *parecen* secretos/DNI reales a propósito (para poder probar
|
|
107
|
+
que los detecta). Un `.pushwardignore` en la raíz del repo (una ruta o
|
|
108
|
+
patrón por línea, comentarios con `#`) excluye esos ficheros del escaneo
|
|
109
|
+
por completo:
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
tests/test_secrets.py
|
|
113
|
+
tests/test_dni_pattern.py
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Úsalo para excepciones concretas y documentadas, no como atajo para ignorar
|
|
117
|
+
avisos reales.
|
|
118
|
+
|
|
119
|
+
## Desarrollo
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
pip install -e ".[dev]"
|
|
123
|
+
ruff check .
|
|
124
|
+
pytest
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Ver [CONTRIBUTING.md](CONTRIBUTING.md) para añadir un check nuevo.
|
|
File without changes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from pushward.plugin import CheckResult, Finding
|
|
7
|
+
from pushward.scanner import read_text
|
|
8
|
+
|
|
9
|
+
_LETTERS = "TRWAGMYFPDXBNJZSQVHLCKE"
|
|
10
|
+
_NIE_PREFIX = {"X": "0", "Y": "1", "Z": "2"}
|
|
11
|
+
|
|
12
|
+
# El lookbehind negativo excluye timestamps ISO8601 con fracción de segundo
|
|
13
|
+
# (p.ej. "...45.73846735Z"): la "Z" de UTC hace que el número parezca DNI
|
|
14
|
+
# ("8 dígitos + letra"), y con miles de líneas de log da la casualidad de que
|
|
15
|
+
# algunos hasta pasan la validación del dígito de control por puro azar.
|
|
16
|
+
# Los bordes no usan \b: el «_» cuenta como letra para \b y «nomina_12345678A.pdf» no casaba.
|
|
17
|
+
# Se admite también el formato con puntos de miles («12.345.678-A»).
|
|
18
|
+
_DNI_RE = re.compile(
|
|
19
|
+
r"(?<![\d.A-Za-z])(\d{8}|\d{1,2}\.\d{3}\.\d{3})[-\s]?([A-Za-z])(?![A-Za-z\d])"
|
|
20
|
+
)
|
|
21
|
+
_NIE_RE = re.compile(r"(?<![\d.A-Za-z])([XYZxyz])(\d{7})[-\s]?([A-Za-z])(?![A-Za-z\d])")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _expected_letter(number: str) -> str:
|
|
25
|
+
return _LETTERS[int(number) % 23]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class DniPatternCheck:
|
|
29
|
+
"""Heurística de DNI/NIE español.
|
|
30
|
+
|
|
31
|
+
No basta con casar el patrón "8 dígitos + letra": ese formato aparece
|
|
32
|
+
todo el tiempo en placeholders/ejemplos inventados (p.ej. "12345678A",
|
|
33
|
+
que ni siquiera es un DNI válido -- su letra de control real es "Z").
|
|
34
|
+
Por eso se valida el dígito de control (módulo 23) antes de reportar
|
|
35
|
+
nada: reduce drásticamente los falsos positivos y solo marca strings
|
|
36
|
+
que son, con alta probabilidad, un DNI/NIE real.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
name = "dni_pattern"
|
|
40
|
+
|
|
41
|
+
def run(self, files: list[Path], repo_path: Path) -> CheckResult:
|
|
42
|
+
findings: list[Finding] = []
|
|
43
|
+
scanned = 0
|
|
44
|
+
for path in files:
|
|
45
|
+
text = read_text(path)
|
|
46
|
+
if text is None:
|
|
47
|
+
continue
|
|
48
|
+
scanned += 1
|
|
49
|
+
rel = str(path.relative_to(repo_path))
|
|
50
|
+
|
|
51
|
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
|
52
|
+
for m in _DNI_RE.finditer(line):
|
|
53
|
+
number, letter = m.group(1).replace(".", "").zfill(8), m.group(2).upper()
|
|
54
|
+
if letter == _expected_letter(number):
|
|
55
|
+
findings.append(
|
|
56
|
+
Finding(
|
|
57
|
+
severity="high",
|
|
58
|
+
title="Posible DNI real",
|
|
59
|
+
detail="Dígito de control válido -- no parece un valor de ejemplo.",
|
|
60
|
+
path=rel,
|
|
61
|
+
line=line_no,
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
for m in _NIE_RE.finditer(line):
|
|
65
|
+
prefix, number, letter = m.group(1).upper(), m.group(2), m.group(3).upper()
|
|
66
|
+
full_number = _NIE_PREFIX[prefix] + number
|
|
67
|
+
if letter == _expected_letter(full_number):
|
|
68
|
+
findings.append(
|
|
69
|
+
Finding(
|
|
70
|
+
severity="high",
|
|
71
|
+
title="Posible NIE real",
|
|
72
|
+
detail="Dígito de control válido -- no parece un valor de ejemplo.",
|
|
73
|
+
path=rel,
|
|
74
|
+
line=line_no,
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
return CheckResult(
|
|
79
|
+
check_name=self.name,
|
|
80
|
+
summary=f"{scanned} fichero(s) analizados, {len(findings)} hallazgo(s).",
|
|
81
|
+
findings=findings,
|
|
82
|
+
)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from pushward.plugin import CheckResult, Finding
|
|
7
|
+
from pushward.scanner import read_text
|
|
8
|
+
|
|
9
|
+
_IP_RE = re.compile(
|
|
10
|
+
r"\b(10\.\d{1,3}\.\d{1,3}\.\d{1,3}"
|
|
11
|
+
r"|172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}"
|
|
12
|
+
r"|192\.168\.\d{1,3}\.\d{1,3})\b"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class PrivateIpsCheck:
|
|
17
|
+
"""IPs de rangos privados (RFC1918): 10.x, 172.16-31.x, 192.168.x."""
|
|
18
|
+
|
|
19
|
+
name = "private_ips"
|
|
20
|
+
|
|
21
|
+
def run(self, files: list[Path], repo_path: Path) -> CheckResult:
|
|
22
|
+
findings: list[Finding] = []
|
|
23
|
+
scanned = 0
|
|
24
|
+
for path in files:
|
|
25
|
+
text = read_text(path)
|
|
26
|
+
if text is None:
|
|
27
|
+
continue
|
|
28
|
+
scanned += 1
|
|
29
|
+
rel = str(path.relative_to(repo_path))
|
|
30
|
+
seen_on_file: set[str] = set()
|
|
31
|
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
|
32
|
+
for m in _IP_RE.finditer(line):
|
|
33
|
+
ip = m.group(0)
|
|
34
|
+
key = f"{ip}:{line_no}"
|
|
35
|
+
if key in seen_on_file:
|
|
36
|
+
continue
|
|
37
|
+
seen_on_file.add(key)
|
|
38
|
+
findings.append(
|
|
39
|
+
Finding(
|
|
40
|
+
severity="info",
|
|
41
|
+
title=f"IP privada: {ip}",
|
|
42
|
+
detail="Puede ser un ejemplo genérico o una IP real de infraestructura -- revisar.",
|
|
43
|
+
path=rel,
|
|
44
|
+
line=line_no,
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
return CheckResult(
|
|
49
|
+
check_name=self.name,
|
|
50
|
+
summary=f"{scanned} fichero(s) analizados, {len(findings)} hallazgo(s).",
|
|
51
|
+
findings=findings,
|
|
52
|
+
)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from pushward.plugin import CheckResult, Finding
|
|
7
|
+
from pushward.scanner import read_text
|
|
8
|
+
|
|
9
|
+
_PATTERNS: list[tuple[str, re.Pattern[str], str]] = [
|
|
10
|
+
("Clave privada (PEM)",
|
|
11
|
+
re.compile(r"-----BEGIN (?:(?:RSA|EC|OPENSSH|DSA|ENCRYPTED|PGP) )?PRIVATE KEY(?: BLOCK)?-----"), "high"),
|
|
12
|
+
("AWS Access Key ID", re.compile(r"\b(?:AKIA|ASIA)[0-9A-Z]{16}\b"), "high"),
|
|
13
|
+
("Token de GitHub", re.compile(r"\b(?:gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{60,})\b"), "high"),
|
|
14
|
+
("Token de Slack", re.compile(r"\bxox[baprse]-[A-Za-z0-9-]{10,}\b"), "high"),
|
|
15
|
+
# Las claves actuales llevan prefijo con guiones (sk-proj-…, sk-ant-api03-…): el patrón antiguo
|
|
16
|
+
# solo veía las sk-<alfanumérico> de antes.
|
|
17
|
+
("Clave de API de OpenAI/Anthropic",
|
|
18
|
+
re.compile(r"\bsk-(?:(?:proj|svcacct|admin|ant-api\d+|ant-admin\d+)-)?[A-Za-z0-9_-]{20,}"), "high"),
|
|
19
|
+
("JWT", re.compile(r"\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b"), "medium"),
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
_ASSIGNMENT = re.compile(
|
|
23
|
+
r"""(?imx)
|
|
24
|
+
^\s*[{\[,]?\s*
|
|
25
|
+
# export X=… (shell), const/let/var (JS), $x = … (PowerShell/PHP/Perl), "x": … (JSON)
|
|
26
|
+
(?:(?:export|const|let|var|readonly|declare|local|my)\s+)?
|
|
27
|
+
[$@]?["']?
|
|
28
|
+
(?:
|
|
29
|
+
[\w.]*(?P<keyword>password|passwd|secret|api_key|apikey|token)["']?
|
|
30
|
+
|
|
|
31
|
+
# dict["password"] = ..., os.environ['API_TOKEN'] = ... -- la clave va
|
|
32
|
+
# entre corchetes y comillas, no como identificador suelto.
|
|
33
|
+
[\w.]*\[\s*['"]\w*(?P<keyword_bracket>password|passwd|secret|api_key|apikey|token)\w*['"]\s*\]
|
|
34
|
+
)
|
|
35
|
+
\s*
|
|
36
|
+
(?:
|
|
37
|
+
# anotación de tipo de Python ("nombre: Tipo = valor") -- sin esto, el
|
|
38
|
+
# separador esperado justo después de la palabra clave sería "str", no
|
|
39
|
+
# "=", y la asignación entera pasaba desapercibida.
|
|
40
|
+
:\s*[A-Za-z_][\w\[\], .]*\s*=
|
|
41
|
+
|
|
|
42
|
+
[:=] # asignación normal (YAML "clave: valor" / Python "clave = valor")
|
|
43
|
+
)
|
|
44
|
+
\s*
|
|
45
|
+
(?:
|
|
46
|
+
['"](?P<quoted>[^'"]{6,})['"] # valor entre comillas: literal, se acepta tal cual
|
|
47
|
+
|
|
|
48
|
+
(?P<unquoted>[^\s'"]{6,}) # sin comillas: se filtra abajo si tiene pinta de código
|
|
49
|
+
)
|
|
50
|
+
"""
|
|
51
|
+
)
|
|
52
|
+
# Un valor sin comillas que contenga estos caracteres es casi siempre una
|
|
53
|
+
# referencia a otra variable/atributo o una llamada a función
|
|
54
|
+
# (`cfg.smtp_password`, `getpass.getpass(...)`), no un secreto literal.
|
|
55
|
+
_CODE_LIKE = re.compile(r"[.()\[\]{},;]")
|
|
56
|
+
_PLACEHOLDER_VALUES = {
|
|
57
|
+
"changeme", "change_me", "your_password", "your-password", "xxxxx",
|
|
58
|
+
"placeholder", "example", "todo", "fixme", "<password>", "<secret>",
|
|
59
|
+
"your_token_here", "insert_here",
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class SecretsCheck:
|
|
64
|
+
"""Claves privadas, tokens de alta confianza (AWS/GitHub/Slack/OpenAI/JWT) y asignaciones de credenciales en claro."""
|
|
65
|
+
|
|
66
|
+
name = "secrets"
|
|
67
|
+
|
|
68
|
+
def run(self, files: list[Path], repo_path: Path) -> CheckResult:
|
|
69
|
+
findings: list[Finding] = []
|
|
70
|
+
scanned = 0
|
|
71
|
+
for path in files:
|
|
72
|
+
text = read_text(path)
|
|
73
|
+
if text is None:
|
|
74
|
+
continue
|
|
75
|
+
scanned += 1
|
|
76
|
+
rel = str(path.relative_to(repo_path))
|
|
77
|
+
|
|
78
|
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
|
79
|
+
for title, pattern, severity in _PATTERNS:
|
|
80
|
+
if pattern.search(line):
|
|
81
|
+
findings.append(
|
|
82
|
+
Finding(
|
|
83
|
+
severity=severity,
|
|
84
|
+
title=f"Posible secreto: {title}",
|
|
85
|
+
detail="Revisar y revocar si es real antes de publicar.",
|
|
86
|
+
path=rel,
|
|
87
|
+
line=line_no,
|
|
88
|
+
)
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
m = _ASSIGNMENT.search(line)
|
|
92
|
+
if m:
|
|
93
|
+
keyword = m.group("keyword") or m.group("keyword_bracket")
|
|
94
|
+
quoted, unquoted = m.group("quoted"), m.group("unquoted")
|
|
95
|
+
if quoted is None and _CODE_LIKE.search(unquoted):
|
|
96
|
+
value = None
|
|
97
|
+
else:
|
|
98
|
+
value = quoted if quoted is not None else unquoted
|
|
99
|
+
if value and value.lower() not in _PLACEHOLDER_VALUES and not value.startswith("{{"):
|
|
100
|
+
findings.append(
|
|
101
|
+
Finding(
|
|
102
|
+
severity="medium",
|
|
103
|
+
title=f"Asignación de credencial en claro ({keyword})",
|
|
104
|
+
detail="Heurística -- puede ser un valor de ejemplo/placeholder real.",
|
|
105
|
+
path=rel,
|
|
106
|
+
line=line_no,
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
return CheckResult(
|
|
111
|
+
check_name=self.name,
|
|
112
|
+
summary=f"{scanned} fichero(s) analizados, {len(findings)} hallazgo(s).",
|
|
113
|
+
findings=findings,
|
|
114
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from pushward.plugin import CheckResult, Finding
|
|
7
|
+
|
|
8
|
+
_SENSITIVE_EXTENSIONS = {".pdf", ".docx", ".doc", ".xlsx", ".xls", ".pptx", ".odt"}
|
|
9
|
+
_SENSITIVE_WORDS = re.compile(
|
|
10
|
+
r"(nomina|payroll|dni|nie|passport|pasaporte|contrato|contract"
|
|
11
|
+
r"|confidencial|confidential|salario|salary|factura|invoice"
|
|
12
|
+
r"|curriculum|cv[-_.]|expediente|historial[-_.]medico)",
|
|
13
|
+
re.IGNORECASE,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class SensitiveFilenamesCheck:
|
|
18
|
+
"""Solo mira nombres de fichero, nunca abre su contenido (PDF/DOCX/etc.
|
|
19
|
+
pueden ser grandes o tener formatos binarios complejos de parsear con
|
|
20
|
+
seguridad -- el nombre ya es una señal suficientemente buena y barata).
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
name = "sensitive_filenames"
|
|
24
|
+
|
|
25
|
+
def run(self, files: list[Path], repo_path: Path) -> CheckResult:
|
|
26
|
+
findings: list[Finding] = []
|
|
27
|
+
for path in files:
|
|
28
|
+
if path.suffix.lower() not in _SENSITIVE_EXTENSIONS:
|
|
29
|
+
continue
|
|
30
|
+
if _SENSITIVE_WORDS.search(path.name):
|
|
31
|
+
rel = str(path.relative_to(repo_path))
|
|
32
|
+
findings.append(
|
|
33
|
+
Finding(
|
|
34
|
+
severity="medium",
|
|
35
|
+
title="Nombre de fichero sensible",
|
|
36
|
+
detail="El nombre sugiere contenido personal/confidencial -- revisar antes de publicar.",
|
|
37
|
+
path=rel,
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
return CheckResult(
|
|
42
|
+
check_name=self.name,
|
|
43
|
+
summary=f"{len(files)} fichero(s) revisados, {len(findings)} hallazgo(s).",
|
|
44
|
+
findings=findings,
|
|
45
|
+
)
|