214 lines
5.0 KiB
Markdown
214 lines
5.0 KiB
Markdown
---
|
|
name: dep-audit
|
|
description: Auditoria de dependencias para projectos Node.js e PHP — vulnerabilidades, pacotes desactualizados, seguranca de ambiente e verificacao de tipos. Obrigatoria antes de commits.
|
|
disable-model-invocation: true
|
|
layer: wiki
|
|
---
|
|
|
|
# /dep-audit - Dependency Security Audit Pre-Commit
|
|
|
|
> **Renomeado de /security-check (12-03-2026).** `/security-check` e agora a skill de auditoria de infraestrutura (plugin infraestrutura).
|
|
|
|
Auditoria de segurança completa para projectos Node.js e PHP. **Obrigatória antes de commits** (Regra CLAUDE.md #47).
|
|
|
|
## Contexto NotebookLM
|
|
|
|
ANTES de executar, consultar notebooks para contexto especializado:
|
|
|
|
| Notebook | ID | Consultar quando |
|
|
|----------|-----|-----------------|
|
|
| Programação | 24947ffa-0019-448a-a340-2f4a275d2eb1 | Para contexto de vulnerabilidades |
|
|
|
|
```
|
|
mcp__notebooklm__notebook_query({
|
|
notebook_id: "24947ffa-0019-448a-a340-2f4a275d2eb1",
|
|
query: "<adaptar ao contexto do pedido do utilizador>"
|
|
})
|
|
```
|
|
|
|
Integrar insights do NotebookLM nas recomendações e decisões.
|
|
|
|
### Procedimentos relacionados
|
|
|
|
- [PROC-DEV-SEC-001-Security-Audit.md](file:///media/ealmeida/Dados/Hub/06-Operacoes/Procedimentos/D7-Tecnologia/Seguranca/PROC-DEV-SEC-001-Security-Audit.md)
|
|
- [PROC-Security-Audit-API-Keys.md](file:///media/ealmeida/Dados/Hub/06-Operacoes/Procedimentos/D7-Tecnologia/Seguranca/PROC-Security-Audit-API-Keys.md)
|
|
|
|
---
|
|
|
|
## Quando Usar
|
|
|
|
### OBRIGATÓRIO:
|
|
- Antes de `git commit`
|
|
- Antes de `git push`
|
|
- Antes de criar Pull Request
|
|
- Antes de deploy para produção
|
|
|
|
### RECOMENDADO:
|
|
- Após `pnpm add <package>` (especialmente AI SDKs)
|
|
- Semanalmente em projectos activos
|
|
- Após actualizar dependências major
|
|
|
|
---
|
|
|
|
## Workflow Completo
|
|
|
|
### 1. Detectar Tipo de Projecto
|
|
|
|
```bash
|
|
# Verificar package managers
|
|
if [ -f "package.json" ]; then
|
|
# Node.js detected
|
|
MANAGER="pnpm" # ou npm/yarn
|
|
elif [ -f "composer.json" ]; then
|
|
# PHP detected
|
|
MANAGER="composer"
|
|
fi
|
|
```
|
|
|
|
### 2. Dependency Security Audit
|
|
|
|
**Node.js:**
|
|
```bash
|
|
pnpm audit --json > ~/.claude-work/security-audit.json
|
|
```
|
|
|
|
**PHP:**
|
|
```bash
|
|
composer audit --format=json > ~/.claude-work/security-audit.json
|
|
```
|
|
|
|
**Parse resultados:**
|
|
- Contar: critical, high, moderate, low
|
|
- Identificar se são directas ou transitivas
|
|
- Listar pacotes afectados
|
|
|
|
### 3. Outdated Dependencies
|
|
|
|
**Node.js:**
|
|
```bash
|
|
pnpm outdated --json > ~/.claude-work/security-outdated.json
|
|
```
|
|
|
|
**Priorizar:**
|
|
- AI SDKs: langchain, together-ai, @tavily/core, @langchain/core
|
|
- Security packages: @auth/*, axios, form-data
|
|
- Framework core: next, react, prisma
|
|
|
|
### 4. Environment Safety Check
|
|
|
|
**Verificar ficheiros:**
|
|
```bash
|
|
# Lista de ficheiros a verificar
|
|
FILES=(.env .env.local .env.production .env.development)
|
|
|
|
for file in "${FILES[@]}"; do
|
|
if [ -f "$file" ]; then
|
|
# Verificar se tem placeholders ou keys reais
|
|
grep -E "(API_KEY|SECRET|TOKEN|PASSWORD)" "$file"
|
|
fi
|
|
done
|
|
```
|
|
|
|
**Validação:**
|
|
- ✅ `API_KEY=placeholder` (safe)
|
|
- ❌ `API_KEY=sk-proj-abc123...` (UNSAFE - real key)
|
|
|
|
### 5. Type Safety (se TypeScript)
|
|
|
|
```bash
|
|
# Verificar se é TypeScript
|
|
if [ -f "tsconfig.json" ]; then
|
|
pnpm type # ou tsc --noEmit
|
|
fi
|
|
```
|
|
|
|
### 6. Análise de Risco AI SDKs
|
|
|
|
**Padrões conhecidos:**
|
|
|
|
| Pacote | Risco | Acção |
|
|
|--------|-------|-------|
|
|
| `langchain` | Alto | Verificar @langchain/core |
|
|
| `together-ai` | Alto | form-data transitiva |
|
|
| `@tavily/core` | Alto | axios transitiva |
|
|
| `@platejs/ai` | Médio | lodash transitiva |
|
|
|
|
**Workflow AI SDKs:**
|
|
```bash
|
|
# 1. Verificar se @langchain/core está desactualizado
|
|
pnpm list @langchain/core
|
|
|
|
# 2. Se versão < 0.3.80 (vulnerável)
|
|
pnpm add @langchain/core@latest
|
|
|
|
# 3. Re-audit
|
|
pnpm audit
|
|
```
|
|
|
|
### 7. Gerar Relatório
|
|
|
|
**Formato output:**
|
|
|
|
```markdown
|
|
## Security Audit Report
|
|
|
|
**Status:** [✅ SAFE | ⚠️ ISSUES FOUND | ❌ CRITICAL]
|
|
**Data:** YYYY-MM-DD HH:MM
|
|
|
|
| Category | Status |
|
|
|----------|--------|
|
|
| Vulnerabilities | [N critical, M high, P moderate, Q low] |
|
|
| Outdated Packages | N total (M major updates) |
|
|
| Environment Safety | ✅ Placeholders only / ❌ Real keys found |
|
|
| Type Safety | ✅ 0 errors / ❌ N errors |
|
|
|
|
### Vulnerabilities Detail
|
|
|
|
#### Critical (N)
|
|
- package@version (via path) - description
|
|
- **Patched:** >=safe-version
|
|
- **Action:** [Override | Update | Replace]
|
|
|
|
#### High (M)
|
|
[...]
|
|
|
|
### Outdated Packages (Priority)
|
|
|
|
**AI SDKs:**
|
|
- langchain: current → latest
|
|
- @langchain/core: current → latest (SECURITY UPDATE)
|
|
|
|
**Framework:**
|
|
- next: current → latest
|
|
|
|
### Action Required
|
|
|
|
**Priority 1 (Critical):**
|
|
1. [Acção específica]
|
|
|
|
**Priority 2 (High):**
|
|
1. [Acção específica]
|
|
|
|
**Priority 3 (Maintenance):**
|
|
1. [Acção específica]
|
|
|
|
### Safe to Commit?
|
|
|
|
[✅ YES | ⚠️ YES (with documentation) | ❌ NO (fix critical first)]
|
|
|
|
**If YES with documentation:**
|
|
```
|
|
git commit -m "feat: feature X
|
|
|
|
Known vulnerabilities (will be resolved):
|
|
- package@version (severity) - waiting for upstream update
|
|
|
|
Mitigation: [explanation]
|
|
"
|
|
```
|
|
|
|
**If NO:**
|
|
Fix critical/high vulnerabilities first. See PROC-DEV-SEC-001 for guidance.
|
|
```
|
|
|
|
### 8. Criar F |