Skip to main content
interlace
Plugin: vercel-ai-securityRules

require-audit-logging

This rule identifies AI SDK calls that aren't preceded by logging statements

Suggests audit logging for AI SDK operations.

📊 Rule Details

PropertyValue
Typesuggestion
Severity⚪ LOW
OWASP AgenticASI10: Logging & Monitoring
CWECWE-778: Insufficient Logging
CVSS4.0
Config Defaultoff (recommended), warn (strict)

🔍 What This Rule Detects

This rule identifies AI SDK calls that aren't preceded by logging statements. Audit logging is important for security monitoring and debugging.

❌ Incorrect Code

// No logging
async function handler() {
  const result = await generateText({
    prompt: userInput,
  });
  return result.text;
}

// Missing audit trail
export async function processRequest(req) {
  await streamText({
    prompt: req.body.message,
  });
}

✅ Correct Code

Hello

⚙️ Options

OptionTypeDefaultDescription
allowInTestsbooleantrueAllow missing logging in test files

🛡️ Why This Matters

Insufficient logging makes it impossible to:

  • Detect abuse - Identify malicious usage patterns
  • Debug issues - Trace problems in production
  • Audit compliance - Prove regulatory compliance
  • Monitor costs - Track API usage

🔄 Changes in the 2026-10-10 FP/FN audit

  • experimental_telemetry / telemetry with isEnabled: true counts as audit logging. Logging calls are matched by callee path (console.log, logger.info, debug(...)), not by substring (showDialog() is not logging).

Known False Negatives

The following patterns are not detected due to static analysis limitations:

Logging in Wrapper Function

Why: Logging in called functions is not visible.

// ❌ NOT DETECTED - Logging in wrapper
await myGenerateText(prompt); // Wrapper has logging

Mitigation: Apply rule to wrapper implementations.

Custom Logger Methods

Why: Non-standard logger methods may not be recognized.

// ❌ NOT DETECTED - Custom logger
myLogger.audit('AI call', { prompt }); // Not in default patterns
await generateText({ prompt });

Mitigation: Configure rule for custom logger method names.

Centralized Logging Middleware

Why: Framework-level logging is not linked.

// ❌ NOT DETECTED (correctly) - Middleware logs all AI calls
app.use(aiAuditMiddleware);

Mitigation: Document centralized logging. Consider rule exception.

Async Logging

Why: Logging scheduled for later may not be detected.

// ❌ NOT DETECTED - Deferred logging
const result = await generateText({ prompt });
queueAuditLog({ prompt, result }); // Async logging

Mitigation: Use synchronous logging before AI calls.

📚 References

Error Message Format

The rule provides LLM-optimized error messages (Compact 2-line format) with actionable security guidance:

⚠️ CWE-778 OWASP:A09 CVSS:5.3 | Insufficient Logging detected | MEDIUM [SOC2,ISO27001,PCI-DSS,NIST-CSF]
   Fix: Review and apply the recommended fix | https://owasp.org/Top10/A09_2021/

Message Components

ComponentPurposeExample
Risk StandardsSecurity benchmarksCWE-778 OWASP:A09 CVSS:5.3
Issue DescriptionSpecific vulnerabilityInsufficient Logging detected
Severity & ComplianceImpact assessmentMEDIUM [SOC2,ISO27001,PCI-DSS,NIST-CSF]
Fix InstructionActionable remediationFollow the remediation steps below
Technical TruthOfficial referenceOWASP Top 10

Did this rule catch something? Star the repo to get new CWE coverage as we ship it — or follow the AI-code-security benchmarks behind these rules.