Skip to content
capacitor-security logo

Capacitor Security with Capsec

capacitor-security

Comprehensive security guide for Capacitor apps using Capsec scanner. Covers 63+ security rules across secrets, storage, network, authentication, cryptography, and platform-specific vulnerabilities. Use this skill when users need to secure their mobile app or run security audits.

SKILL.md

Full skill instructions

Capacitor Security with Capsec

Zero-config security scanning for Capacitor and Ionic apps.

When to Use This Skill

  • User wants to secure their app
  • User asks about security vulnerabilities
  • User needs to run security audit
  • User has hardcoded secrets
  • User needs CI/​CD security scanning
  • User asks about OWASP mobile security

Quick Start with Capsec

Run Security Scan

# Scan current directory (no installation needed)
bunx capsec scan

# Scan specific path
bunx capsec scan ./​my-app

# CI mode (exit code 1 on high/​critical issues)
bunx capsec scan --ci

Output Formats

# CLI output (default)
bunx capsec scan

# JSON report
bunx capsec scan --output json --output-file report.json

# HTML report
bunx capsec scan --output html --output-file security-report.html

Filtering

# Only critical and high severity
bunx capsec scan --severity high

# Specific categories
bunx capsec scan --categories secrets,network,storage

# Exclude test files
bunx capsec scan --exclude "**/​test/​**,**/​*.spec.ts"

Security Rules Reference

Secrets Detection (SEC)

RuleSeverityDescription
SEC001CriticalHardcoded API Keys & Secrets
SEC002HighExposed .env File

What Capsec Detects:

  • AWS Access Keys
  • Google API Keys
  • Firebase Keys
  • Stripe Keys
  • GitHub Tokens
  • JWT Secrets
  • Database Credentials
  • 30+ secret patterns

Fix Example:

// BAD - Hardcoded API key
const API_KEY = 'sk_live_abc123xyz';

// GOOD - Use environment variables
import { Env } from '@capgo/​capacitor-env';
const API_KEY = await Env.get({ key: 'API_KEY' });

Storage Security (STO)

RuleSeverityDescription
STO001HighUnencrypted Sensitive Data in Preferences
STO002HighlocalStorage Usage for Sensitive Data
STO003MediumSQLite Database Without Encryption
STO004MediumFilesystem Storage of Sensitive Data
STO005LowInsecure Data Caching
STO006HighKeychain/​Keystore Not Used for Credentials

Fix Example:

// BAD - Plain preferences for tokens
import { Preferences } from '@capacitor/​preferences';
await Preferences.set({ key: 'auth_token', value: token });

// GOOD - Use secure storage
import { NativeBiometric } from '@capgo/​capacitor-native-biometric';
await NativeBiometric.setCredentials({
  username: email,
  password: token,
  server: 'api.myapp.com',
});

Network Security (NET)

RuleSeverityDescription
NET001CriticalHTTP Cleartext Traffic
NET002HighSSL/​TLS Certificate Pinning Missing
NET003HighCapacitor Server Cleartext Enabled
NET004MediumInsecure WebSocket Connection
NET005MediumCORS Wildcard Configuration
NET006MediumInsecure Deep Link Validation
NET007LowCapacitor HTTP Plugin Misuse
NET008HighSensitive Data in URL Parameters

Fix Example:

// BAD - HTTP in production
const config: CapacitorConfig = {
  server: {
    cleartext: true,  // Never in production!
  },
};

// GOOD - HTTPS only
const config: CapacitorConfig = {
  server: {
    cleartext: false,
    // Only allow specific domains
    allowNavigation: ['https://api.myapp.com'],
  },
};

Capacitor-Specific (CAP)

RuleSeverityDescription
CAP001HighWebView Debug Mode Enabled
CAP002MediumInsecure Plugin Configuration
CAP003LowVerbose Logging in Production
CAP004HighInsecure allowNavigation
CAP005CriticalNative Bridge Exposure
CAP006CriticalEval Usage with User Input
CAP007MediumMissing Root/​Jailbreak Detection
CAP008LowInsecure Plugin Import
CAP009MediumLive Update Security
CAP010HighInsecure postMessage Handler

Fix Example:

// BAD - Debug mode in production
const config: CapacitorConfig = {
  ios: {
    webContentsDebuggingEnabled: true,  // Remove in production!
  },
  android: {
    webContentsDebuggingEnabled: true,  // Remove in production!
  },
};

// GOOD - Only in development
const config: CapacitorConfig = {
  ios: {
    webContentsDebuggingEnabled: process.env.NODE_ENV === 'development',
  },
};

Android Security (AND)

RuleSeverityDescription
AND001HighAndroid Cleartext Traffic Allowed
AND002MediumAndroid Debug Mode Enabled
AND003MediumInsecure Android Permissions
AND004LowAndroid Backup Allowed
AND005HighExported Components Without Permission
AND006MediumWebView JavaScript Enabled Without Safeguards
AND007CriticalInsecure WebView addJavascriptInterface
AND008CriticalHardcoded Signing Key

Fix AndroidManifest.xml:

<!-- BAD -->
<application android:usesCleartextTraffic="true">

<!-- GOOD -->
<application
    android:usesCleartextTraffic="false"
    android:allowBackup="false"
    android:networkSecurityConfig="@xml/​network_security_config">

network_security_config.xml:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="false">
        <domain includeSubdomains="true">api.myapp.com</​domain>
        <pin-set>
            <pin digest="SHA-256">your-pin-hash</​pin>
        </​pin-set>
    </​domain-config>
</​network-security-config>

iOS Security (IOS)

RuleSeverityDescription
IOS001HighApp Transport Security Disabled
IOS002MediumInsecure Keychain Access
IOS003MediumURL Scheme Without Validation
IOS004LowiOS Pasteboard Sensitive Data
IOS005MediumInsecure iOS Entitlements
IOS006LowBackground App Refresh Data Exposure
IOS007MediumMissing iOS Jailbreak Detection
IOS008LowScreenshots Not Disabled for Sensitive Screens

Fix Info.plist:

<!-- BAD - Disables ATS -->
<key>NSAppTransportSecurity</​key>
<dict>
    <key>NSAllowsArbitraryLoads</​key>
    <true/>
</​dict>

<!-- GOOD - Specific exceptions only -->
<key>NSAppTransportSecurity</​key>
<dict>
    <key>NSExceptionDomains</​key>
    <dict>
        <key>legacy-api.example.com</​key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</​key>
            <true/>
            <key>NSExceptionMinimumTLSVersion</​key>
            <string>TLSv1.2</​string>
        </​dict>
    </​dict>
</​dict>

Authentication (AUTH)

RuleSeverityDescription
AUTH001CriticalWeak JWT Validation
AUTH002HighInsecure Biometric Implementation
AUTH003HighWeak Random Number Generation
AUTH004MediumMissing Session Timeout
AUTH005HighOAuth State Parameter Missing
AUTH006CriticalHardcoded Credentials in Auth

Fix Example:

// BAD - No JWT validation
const decoded = jwt.decode(token);

// GOOD - Verify JWT signature
const decoded = jwt.verify(token, publicKey, {
  algorithms: ['RS256'],
  issuer: 'https://auth.myapp.com',
  audience: 'myapp',
});

WebView Security (WEB)

RuleSeverityDescription
WEB001CriticalWebView JavaScript Injection
WEB002MediumUnsafe iframe Configuration
WEB003MediumExternal Script Loading
WEB004MediumContent Security Policy Missing
WEB005LowTarget _blank Without noopener

Fix - Add CSP:

<!-- index.html -->
<meta http-equiv="Content-Security-Policy" content="
  default-src 'self';
  script-src 'self';
  style-src 'self' 'unsafe-inline';
  img-src 'self' data: https:;
  connect-src 'self' https://api.myapp.com;
  font-src 'self';
  frame-ancestors 'none';
">

Cryptography (CRY)

RuleSeverityDescription
CRY001CriticalWeak Cryptographic Algorithm
CRY002CriticalHardcoded Encryption Key
CRY003HighInsecure Random IV Generation
CRY004HighWeak Password Hashing

Fix Example:

// BAD - Weak algorithm
const encrypted = CryptoJS.DES.encrypt(data, key);

// GOOD - Strong algorithm
const encrypted = CryptoJS.AES.encrypt(data, key, {
  mode: CryptoJS.mode.GCM,
  padding: CryptoJS.pad.Pkcs7,
});

// BAD - Hardcoded key
const key = 'my-secret-key-123';

// GOOD - Derived key
const key = await crypto.subtle.deriveKey(
  { name: 'PBKDF2', salt, iterations: 100000, hash: 'SHA-256' },
  baseKey,
  { name: 'AES-GCM', length: 256 },
  false,
  ['encrypt', 'decrypt']
);

Logging (LOG)

RuleSeverityDescription
LOG001HighSensitive Data in Console Logs
LOG002LowConsole Logs in Production

Fix Example:

// BAD - Logging sensitive data
console.log('User password:', password);
console.log('Token:', authToken);

// GOOD - Redact sensitive data
console.log('User authenticated:', userId);
// Use conditional logging
if (process.env.NODE_ENV === 'development') {
  console.debug('Debug info:', data);
}

CI/​CD Integration

GitHub Actions

name: Security Scan

on: [push, pull_request]

jobs:
  security:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/​checkout@v4

      - uses: oven-sh/​setup-bun@v1

      - name: Run Capsec Security Scan
        run: bunx capsec scan --ci --output json --output-file security-report.json

      - name: Upload Security Report
        uses: actions/​upload-artifact@v4
        if: always()
        with:
          name: security-report
          path: security-report.json

GitLab CI

security-scan:
  image: oven/​bun:latest
  script:
    - bunx capsec scan --ci
  artifacts:
    reports:
      security: security-report.json
  only:
    - merge_requests
    - main

Configuration

capsec.config.json

{
  "exclude": [
    "**/​node_modules/​**",
    "**/​dist/​**",
    "**/​*.test.ts",
    "**/​*.spec.ts"
  ],
  "severity": "low",
  "categories": [],
  "rules": {
    "LOG002": {
      "enabled": false
    },
    "SEC001": {
      "severity": "critical"
    }
  }
}

Initialize Config

bunx capsec init

Root/​Jailbreak Detection

import { IsRoot } from '@capgo/​capacitor-is-root';

async function checkDeviceSecurity() {
  const { isRooted } = await IsRoot.isRooted();

  if (isRooted) {
    // Option 1: Warn user
    showWarning('Device security compromised');

    // Option 2: Restrict features
    disableSensitiveFeatures();

    // Option 3: Block app (for high-security apps)
    blockApp();
  }
}

Security Checklist

Before Release

  • Run bunx capsec scan --severity high
  • Remove all console.log statements
  • Disable WebView debugging
  • Remove development URLs
  • Verify no hardcoded secrets
  • Enable certificate pinning
  • Implement root/​jailbreak detection
  • Add Content Security Policy
  • Use secure storage for credentials
  • Enable ProGuard (Android)
  • Verify ATS settings (iOS)

Ongoing

  • Run security scans in CI/​CD
  • Monitor for new vulnerabilities
  • Update dependencies regularly
  • Review third-party plugins
  • Audit authentication flows

Resources

More Security skills

supabase logo
Security

supabase

Handles the full Supabase workflow from schema changes to deployment, with built-in security guardrails that catch common traps like RLS...

2.7K 308.9K
View

Comprehensive guides and best practices for Neon Serverless Postgres, covering setup, connection methods, authentication, and platform APIs.

98 216.2K
View

Guide for setting up and using Firebase Authentication. Use this skill when the user's app requires user sign-in, user management, or secure data access using auth rules.

462 163.8K
View

A skill to evaluate how secure Firestore security rules are. Use this when Firestore security rules are updated to ensure that the generated rules are extremely secure and robust.

462 127.7K
View

Official skill for integrating Firebase AI Logic (Gemini API) into web applications. Covers setup, multimodal inference, structured output, and security.

462 125.1K
View

Complete Better Auth server and client setup with database adapters, session management, plugins, and security configuration.

222 118.2K
View

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g. "deploy to vercel", "set up vercel", "add environment variables to vercel".

31.9K 116.1K
View
cloudflare logo
Security

cloudflare

Complete Cloudflare platform integration with decision trees for compute, storage, AI, networking, security, and infrastructure-as-code.

3K 110.7K
View

Run Azure compliance and security audits with azqr plus Key Vault expiration checks. Covers best-practice assessment, resource review, policy/compliance validation, and security posture checks. WHEN: compliance scan, security audit, BEFORE running azqr (compliance cli tool), Azure best practices, Key Vault expiration check, expired certificates, expiring secrets, orphaned resources, compliance assessment.

253 103K
View
gws-gmail logo
Security

gws-gmail

Send, read, and manage Gmail messages, drafts, labels, and account settings.

31.2K 78.9K
View

Comprehensive website auditing across 230+ rules in 21 categories including SEO, performance, security, and accessibility.

94 72.3K
View
gws-shared logo
Security

gws-shared

Shared authentication, CLI syntax, and output formatting patterns for gws Google Workspace commands.

31.2K 63.4K
View

Security AI tools

StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
GeoSpy logo
Security

GeoSpy

GeoSpy: Pricing, Features, FAQs, and Alternatives for AI Teams

Free
View

Detect AI-generated voices to protect against audio fraud.

Paid
View

Ensure Your Content's Originality with AI Plagiarism Checker

Freemium
View
Img Upscaler logo
Security

Img Upscaler

Upscale images by 400% without quality loss

Freemium
View
AICheatCheck logo
Security

AICheatCheck

Accurately Detect AI-Generated Content with TheChecker.AI

Free
View
D
Security

Detect GPT

Chrome extension that detects and flags AI-generated content

Free
View