Przejdź do treści
Biblioteka skilli
Bezpieczeństwo · Przegląd i audyt

ts-security

/ts-security

Przeprowadza przegląd bezpieczeństwa kodu w TypeScript, Node.js i NestJS, z oceną CVSS i wzorcami bezpiecznego kodowania.

Licencja
MIT
Ostatnia zmiana repozytorium
12.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 12.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Przeprowadza przegląd bezpieczeństwa kodu w TypeScript, Node.js i NestJS, z oceną CVSS i wzorcami bezpiecznego kodowania.

Wyzwalacze z opisu

security auditvulnerabilityinjectionXSSOWASP
Oryginalny opis (EN)

ACTIVATE when conducting security assessments, code review for vulnerabilities, or CVSS scoring in TypeScript/Node.js/NestJS projects. ACTIVATE for 'security audit', 'vulnerability', 'injection', 'XSS', 'OWASP' in a TS context. Provides TS/NestJS-specific security patterns (Drizzle parameterized queries, JWT setup, bcrypt rounds, execFile over exec, path traversal, Zod env validation, CSRF). Loads alongside security-audit:security-audit (comprehensive baseline) and audit:security-overrides (personal conventions). DO NOT use for: general code quality, performance optimization, authentication fl

Jak działa

  1. Standards
  2. SQL Injection Prevention
  3. XSS Prevention
  4. JWT Security
  5. Password Hashing
  6. Command Injection Prevention
  7. Path Traversal Prevention
  8. Environment & Secrets
  9. CSRF Protection
  10. Security Tooling
Sekcje z nagłówków SKILL.md, w oryginale · 190 linii, 730 słów
Podgląd SKILL.md
---
name: ts-security
description: "ACTIVATE when conducting security assessments, code review for vulnerabilities, or CVSS scoring in TypeScript/Node.js/NestJS projects. ACTIVATE for 'security audit', 'vulnerability', 'injection', 'XSS', 'OWASP' in a TS context. Provides TS/NestJS-specific security patterns (Drizzle parameterized queries, JWT setup, bcrypt rounds, execFile over exec, path traversal, Zod env validation, CSRF). Loads alongside security-audit:security-audit (comprehensive baseline) and audit:security-overrides (personal conventions). DO NOT use for: general code quality, performance optimization, authentication flow design."
---

# Security — TypeScript / Node.js Examples

> Part of the audit overlay pattern. Companion skills:
> - `security-audit:security-audit` (upstream baseline — OWASP/CWE/CVSS, 61 references)
> - `audit:security-overrides` (personal conventions: stack scope, FP filters, output format)
>
> This skill provides TS-specific code examples for the patterns the upstream covers conceptually.

## Standards

- **OWASP Top 10** (2021)
- **CWE Top 25** (2025)
- **CVSS v3.1 / v4.0** for risk scoring

## SQL Injection Prevention

**Always use Drizzle parameterized queries.** Never interpolate user input into SQL.

```typescript
// ❌ AVOID - String interpolation in SQL
const result = await db.execute(
  `SELECT * FROM tenants WHERE email = '${email}'`
);

// ✅ CORRECT - Drizzle parameterized query
const result = await db
  .select()
  .from(tenants)
  .where(eq(tenants.email, email));

// ✅ CORRECT - Raw SQL with placeholder
import { sql } from 'drizzle-orm';
const result = await db.execute(
  sql`SELECT * FROM tenants WHERE email = ${email}`
);
```

## XSS Prevention

```typescript
// ✅ React/JSX auto-escapes by default — safe
return <p>{userInput}</p>;

// ❌ AVOID - Bypasses auto-escaping
return <div dangerouslySetInnerHTML={{ __html: userInput }} />;

// ✅ CORRECT - If HTML rendering needed, sanitize first
import DOMPurify from 'dompurify';
const clean = DOMPurify.sanitize(userInput);
return <div dangerouslySetInnerHTML={{ __html: clean }} />;
```

## JWT Security

```typescript
// ❌ AVOID - No expiration, weak secret
const token = jwt.sign(payload, 'secret');

// ✅ CORRECT - Strong secret, expiration, algorithm specified
const token = jwt.sign(payload, process.env.JWT_SECRET, {
  expiresIn: '1h',
  algorithm: 'HS256',
});

// ✅ CORRECT - Validate with explicit algorithms
const decoded = jwt.verify(token, process.env.JWT_SECRET, {
  algorithms: ['HS256'],
});
```

## Password Hashing

```typescript
import * as bcrypt from 'bcrypt';

// ✅ CORRECT - bcrypt with sufficient rounds
const SALT_ROUNDS = 12;
const hash = await bcrypt.hash(password, SALT_ROUNDS);
const isValid = await bcrypt.compare(password, hash);

// ❌ AVOID - MD5, SHA-1, SHA-256 without salt
import { createHash } from 'crypto';
const hash = createHash('sha256').update(password).digest('hex');
```

## Command Injection Prevention

```typescript
// ❌ AVOID - Shell injection via child_process.exec
// exec(`convert ${userInput} output.png`);
// exec() spawns a shell, allowing injection via metacharacters

// ✅ CORRECT - execFile prevents shell injection (no shell involved)
import { execFile } from 'child_process';

execFile('convert', [userInput, 'output.png'], (error, stdout) => {
  // Arguments are passed as array, not interpolated into a shell command
});
```

## Path Traversal Prevention

```typescript
import { resolve, normalize } from 'path';

// ❌ AVOID - User input directly in path
const filePath = `./uploads/${req.params.filename}`;

// ✅ CORRECT - Normalize and verify containment
const UPLOAD_DIR = resolve('./uploads');
const requested = resolve(UPLOAD_DIR, req.params.filename);

if (!requested.startsWith(UPLOAD_DIR)) {
  throw new ForbiddenException('Path traversal detected');
}
```

## Environment & Secrets

```typescript
// ❌ AVOID - Secrets hardcoded
const API_KEY = 'sk-1234567890abcdef';

// ✅ CORRECT - From environment, validated at startup
import { z } from 'zod';

const EnvSchema = z.object({
  JWT_SECRET: z.string().min(32),
  DATABASE_URL: z.string().url(),
  API_KEY: z.string().min(16),
});

const env = EnvSchema.parse(process.env);
```

## CSRF Protection

```typescript
// ✅ NestJS - Use CSRF middleware for state-changing endpoints
// For API-only (JWT auth): CSRF is not needed (no cookies)
// For session-based auth: enable CSRF tokens

// ✅ SameSite cookies
response.cookie('session', token, {
  httpOnly: true,
  secure: true,
  sameSite: 'strict',
});
```

## Security Tooling

```bash
# Dependency audit
pnpm audit

# ESLint security rules
pnpm add -D eslint-plugin-security

# Snyk scanning
npx snyk test
```

## Security Checklist

- [ ] bcrypt (12+ rounds) for passwords
- [ ] Drizzle parameterized queries everywhere (no string interpolation)
- [ ] JWT with expiration, strong secret, explicit algorithm
- [ ] No `dangerouslySetInnerHTML` without DOMPurify
- [ ] `execFile` instead of `exec` for system commands
- [ ] Path traversal check on all file operations
- [ ] Secrets in environment variables, validated with Zod at startup
- [ ] `httpOnly`, `secure`, `sameSite: 'strict'` on cookies
- [ ] `pnpm audit` in CI pipeline
- [ ] Security headers (HSTS, CSP, X-Content-Type-Options) via Helmet

## Quick Reference

| Vulnerability | Mitigation |
|--------------|------------|
| SQL Injection | Drizzle queries, `sql` template tag |
| XSS | JSX auto-escaping, DOMPurify if needed |
| JWT flaws | Expiration, strong secret, explicit algorithm |
| Weak passwords | bcrypt 12+ rounds |
| Command injection | `execFile` (no shell) |
| Path traversal | `resolve` + `startsWith` check |
| Secrets in code | Env vars + Zod validation |
| CSRF | SameSite cookies, CSRF tokens for sessions |

Wersje

W bazie nie ma innych skilli o nazwie ts-security.

Migawka bazy z 13.11.2026 · wersja paczki ce888f38a3fa (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100security-overrides
    Dopasowuje audyt bezpieczeństwa do osobistych projektów w PHP Symfony i TypeScript NestJS: filtry fałszywych alarmów i format wyników.
  • 100security
    Podpowiada zasady bezpieczeństwa aplikacji i OWASP Top 10: przegląd kodu, logowanie, sekrety, nagłówki i zapobieganie wstrzyknięciom.
  • 90security-audit
    Sprawdza bezpieczeństwo kodu i konfiguracji, zależności pod kątem CVE oraz typowe błędy OWASP, takie jak wstrzyknięcia, XSS i CSRF.
  • 100security-audit
    Prowadzi oceny bezpieczeństwa (OWASP Top 10, API i LLM, CWE Top 25, scoring CVSS) dla PHP i TYPO3, API, frontendu, IaC Terraform, K8s i Docker, AWS, konfiguracji agentów AI i zależności.
  • 100nestjs-security
    Wdraża uwierzytelnianie JWT, guardy RBAC, utwardzanie Helmetem i haszowanie Argon2 w NestJS, w tym ochronę CSRF i nagłówki bezpieczeństwa.
  • 90security-audit
    Przegląda bezpieczeństwo kodu, audytuje zależności pod kątem CVE oraz sprawdza konfigurację, sekrety i wzorce uwierzytelniania.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.