Documentation menuMenu da documentação

$ cat docs/lint.md

Security lintLint de segurança

Static analysis of route handlers on the Oxc parser. It catches lookups by id without the owner (BOLA), raw rows sent to the client, request data in logs and hardcoded secrets.Análise estática dos handlers de rota com o parser Oxc. Pega consulta por id sem o dono (BOLA), linha crua enviada ao cliente, dado da requisição no log e segredo escrito no código.

Run itRodar

terminal
npm install -D @tupik/lint
npx tupik-lint src
npx tupik-lint src --format sarif --output tupik-lint.sarif   # GitHub code scanning
npm install -D @tupik/lint
npx tupik-lint src
npx tupik-lint src --format sarif --output tupik-lint.sarif   # code scanning do GitHub

Exit code 0 when clean or only warnings, 1 with at least one error, 2 for bad usage or config. Output: text, json or sarif. node_modules, dist, build, coverage and .d.ts files are always skipped. npx tupik lint runs the same binary.

Código de saída 0 quando limpo ou só com avisos, 1 com ao menos um erro, 2 para uso ou configuração inválidos. Saída: text, json ou sarif. node_modules, dist, build, coverage e arquivos .d.ts são sempre ignorados. npx tupik lint roda o mesmo binário.

RulesRegras

RuleRegraDefaultPadrãoCatchesO que pega
tupik/no-unscoped-lookupwarnLookup by a route param (Drizzle where, D1 bind, Prisma finders, query, sql templates) without owner, tenant or principal in the same filter and without access: { owner }.Consulta por param da rota (Drizzle where, D1 bind, Prisma, query, template sql) sem dono, tenant ou principal no mesmo filtro e sem access: { owner }.
tupik/no-raw-row-responsewarnHandler returns SELECT *, select() or returning() without columns, Prisma without select. Skipped when the route declares schema.response.Handler devolve SELECT *, select() ou returning() sem colunas, Prisma sem select. Ignorado quando a rota declara schema.response.
tupik/no-log-request-datawarnconsole or logger with ctx.body, request headers, authorization or cookie values, tokens or passwords.console ou logger com ctx.body, headers da requisição, valor de authorization ou cookie, token ou senha.
tupik/no-hardcoded-secreterrorKnown key formats (Stripe, GitHub, AWS, Slack, Google, OpenAI and Anthropic, PEM, JWT) anywhere; random values in names like secret, token, apiKey, password.Formatos conhecidos de chave (Stripe, GitHub, AWS, Slack, Google, OpenAI e Anthropic, PEM, JWT) em qualquer lugar; valor aleatório em nomes como secret, token, apiKey, password.
notes.ts
// reported: any signed-in user reads any document
.get('/:id', { access: 'authenticated', handler: (ctx) => db.select().from(docs).where(eq(docs.id, ctx.params.id)) })

// fixed: the owner rule
.get('/:id', { access: { owner: (ctx) => ownerOf(ctx.params.id) }, handler: (ctx) => loadDoc(ctx.params.id) })

// fixed: the owner in the same filter
.get('/:id', {
  access: 'authenticated',
  handler: (ctx) =>
    db.select({ id: docs.id, title: docs.title }).from(docs)
      .where(and(eq(docs.id, ctx.params.id), eq(docs.ownerId, ctx.principal.id))),
})
// reportado: qualquer usuário logado lê qualquer documento
.get('/:id', { access: 'authenticated', handler: (ctx) => db.select().from(docs).where(eq(docs.id, ctx.params.id)) })

// corrigido: a regra de dono
.get('/:id', { access: { owner: (ctx) => ownerOf(ctx.params.id) }, handler: (ctx) => loadDoc(ctx.params.id) })

// corrigido: o dono no mesmo filtro
.get('/:id', {
  access: 'authenticated',
  handler: (ctx) =>
    db.select({ id: docs.id, title: docs.title }).from(docs)
      .where(and(eq(docs.id, ctx.params.id), eq(docs.ownerId, ctx.principal.id))),
})

Configuration and APIConfiguração e API

tupik-lint.config.json in the working directory (or --config <file>), else the tupikLint field of package.json. Severities: off, warn, error.

tupik-lint.config.json no diretório de trabalho (ou --config <arquivo>), senão o campo tupikLint do package.json. Gravidades: off, warn, error.

tupik-lint.config.json
{
  "rules": { "tupik/no-raw-row-response": "off" },
  "ignore": ["**/__tests__/**"]
}
lint.ts
import { lintFiles, lintSource } from '@tupik/lint';

const diagnostics = lintSource(source, { filename: 'routes.ts', config: { rules: { 'tupik/no-raw-row-response': 'off' } } });
const { errorCount, warningCount } = await lintFiles(['src'], { cwd: process.cwd() });

LimitsLimites

  • The analysis is syntactic and per file. A lookup inside a repository function in another file is not followed.
  • Treat findings as review prompts. The runtime guarantee is access: { owner }.
  • Test fixtures with fake tokens show up in no-hardcoded-secret: ignore them in the config.
  • A análise é sintática e por arquivo. Consulta escondida numa função de repositório em outro arquivo não é seguida.
  • Trate os achados como pontos de revisão. A garantia em execução é o access: { owner }.
  • Fixtures de teste com token falso aparecem no no-hardcoded-secret: ignore-as na configuração.