@capgo/capgo-sec 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ name: Bump version
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ test:
10
+ if: ${{ !startsWith(github.event.head_commit.message, 'chore(release):') }}
11
+ uses: ./.github/workflows/ci.yml
12
+
13
+ bump-version:
14
+ needs: [test]
15
+ if: ${{ !startsWith(github.event.head_commit.message, 'chore(release):') }}
16
+ runs-on: ubuntu-latest
17
+ name: Bump version and create tag
18
+ steps:
19
+ - name: Checkout
20
+ uses: actions/checkout@v4
21
+ with:
22
+ fetch-depth: 0
23
+ token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
24
+
25
+ - name: Setup Bun
26
+ uses: oven-sh/setup-bun@v2
27
+ with:
28
+ bun-version: latest
29
+
30
+ - name: Install dependencies
31
+ run: bun install
32
+
33
+ - name: Build
34
+ run: bun run build
35
+
36
+ - name: Git config
37
+ run: |
38
+ git config --local user.name "github-actions[bot]"
39
+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
40
+
41
+ - name: Create version bump
42
+ run: bunx standard-version --skip.changelog
43
+
44
+ - name: Push to origin
45
+ run: |
46
+ CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
47
+ remote_repo="https://${GITHUB_ACTOR}:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
48
+ git pull $remote_repo $CURRENT_BRANCH
49
+ git push $remote_repo HEAD:$CURRENT_BRANCH --follow-tags --tags
50
+
51
+ publish:
52
+ needs: [bump-version]
53
+ runs-on: ubuntu-latest
54
+ permissions:
55
+ contents: read
56
+ id-token: write
57
+ steps:
58
+ - uses: actions/checkout@v4
59
+ with:
60
+ ref: main
61
+ fetch-depth: 0
62
+
63
+ - name: Setup Bun
64
+ uses: oven-sh/setup-bun@v2
65
+ with:
66
+ bun-version: latest
67
+
68
+ - name: Setup Node.js
69
+ uses: actions/setup-node@v4
70
+ with:
71
+ node-version: '20'
72
+ registry-url: 'https://registry.npmjs.org'
73
+
74
+ - name: Install dependencies
75
+ run: bun install
76
+
77
+ - name: Build
78
+ run: bun run build
79
+
80
+ - name: Publish to npm
81
+ run: npm publish --provenance --access public
82
+ env:
83
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,44 @@
1
+ name: CI
2
+
3
+ on:
4
+ workflow_call:
5
+ push:
6
+ branches: [main]
7
+ pull_request:
8
+ branches: [main]
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Setup Bun
17
+ uses: oven-sh/setup-bun@v1
18
+ with:
19
+ bun-version: latest
20
+
21
+ - name: Install dependencies
22
+ run: bun install
23
+
24
+ - name: Run tests
25
+ run: bun test
26
+
27
+ - name: Build
28
+ run: bun run build
29
+
30
+ lint:
31
+ runs-on: ubuntu-latest
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+
35
+ - name: Setup Bun
36
+ uses: oven-sh/setup-bun@v1
37
+ with:
38
+ bun-version: latest
39
+
40
+ - name: Install dependencies
41
+ run: bun install
42
+
43
+ - name: Type check
44
+ run: bunx tsc --noEmit
package/AGENTS.md ADDED
@@ -0,0 +1,125 @@
1
+ # AGENTS.md
2
+
3
+ This file provides guidance to AI agents and contributors working on this Capacitor plugin.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Install dependencies
9
+ bun install
10
+
11
+ # Build the plugin (TypeScript + Rollup + docgen)
12
+ bun run build
13
+
14
+ # Full verification (iOS, Android, Web)
15
+ bun run verify
16
+
17
+ # Format code (ESLint + Prettier + SwiftLint)
18
+ bun run fmt
19
+
20
+ # Lint without fixing
21
+ bun run lint
22
+ ```
23
+
24
+ ## Development Workflow
25
+
26
+ 1. **Install** - `bun install` (never use npm)
27
+ 2. **Build** - `bun run build` compiles TypeScript, generates docs, and bundles with Rollup
28
+ 3. **Verify** - `bun run verify` builds for iOS, Android, and Web. Always run this before submitting work
29
+ 4. **Format** - `bun run fmt` auto-fixes ESLint, Prettier, and SwiftLint issues
30
+ 5. **Lint** - `bun run lint` checks code quality without modifying files
31
+
32
+ ### Individual Platform Verification
33
+
34
+ ```bash
35
+ bun run verify:ios
36
+ bun run verify:android
37
+ bun run verify:web
38
+ ```
39
+
40
+ ### Example App
41
+
42
+ If an `example-app/` directory exists, you can test the plugin locally:
43
+
44
+ ```bash
45
+ cd example-app
46
+ bun install
47
+ bun run start
48
+ ```
49
+
50
+ The example app references the plugin via `file:..`. Use `bunx cap sync <platform>` to sync native platforms.
51
+
52
+ ## Project Structure
53
+
54
+ - `src/definitions.ts` - TypeScript interfaces and types (source of truth for API docs)
55
+ - `src/index.ts` - Plugin registration
56
+ - `src/web.ts` - Web implementation
57
+ - `ios/Sources/` - iOS native code (Swift)
58
+ - `android/src/main/` - Android native code (Java/Kotlin)
59
+ - `dist/` - Generated output (do not edit manually)
60
+ - `Package.swift` - SwiftPM definition
61
+ - `*.podspec` - CocoaPods spec
62
+
63
+ ## iOS Package Management
64
+
65
+ We always support both **CocoaPods** and **Swift Package Manager (SPM)**. Every plugin must ship a valid `*.podspec` and `Package.swift`. Do not remove or break either integration — users depend on both.
66
+
67
+ ## API Documentation
68
+
69
+ API docs in the README are auto-generated from JSDoc in `src/definitions.ts`. **Never edit the `<docgen-index>` or `<docgen-api>` sections in README.md directly.** Instead, update `src/definitions.ts` and run `bun run docgen` (also runs as part of `bun run build`).
70
+
71
+ ## Versioning
72
+
73
+ The plugin major version follows the Capacitor major version (e.g., plugin v8 for Capacitor 8). **We only ship breaking changes when a new Capacitor native major version is released.** All other changes must be backward compatible.
74
+
75
+ ## Changelog
76
+
77
+ `CHANGELOG.md` is managed automatically by CI/CD. Do not edit it manually.
78
+
79
+ ## Pull Request Guidelines
80
+
81
+ We welcome contributions, including AI-generated pull requests. Every PR must include:
82
+
83
+ ### Required Sections
84
+
85
+ 1. **What** - What does this PR change?
86
+ 2. **Why** - What is the reason for this change?
87
+ 3. **How** - How did you approach the implementation?
88
+ 4. **Testing** - What did you test? How did you verify it works?
89
+ 5. **Not Tested** - What is not yet tested or needs further validation?
90
+
91
+ ### Rules
92
+
93
+ - **No breaking changes** unless aligned with a new Capacitor major release.
94
+ - Run `bun run verify` and `bun run fmt` before opening a PR. CI will catch failures, but catching them locally saves time.
95
+ - If you are an AI agent, that is perfectly fine. Just be transparent about it. We care that the code is correct and helpful, not who wrote it.
96
+ - We review PRs on a best-effort basis. We may request changes — you are expected to address them for the PR to be merged.
97
+ - We use automated code review tools (CodeRabbit, and others). You will need to respond to their feedback and resolve any issues they raise.
98
+ - We have automatic releases. Once merged, your change will ship in the next release cycle.
99
+
100
+ ### PR Template
101
+
102
+ ```
103
+ ## What
104
+ - [Brief description of the change]
105
+
106
+ ## Why
107
+ - [Motivation for this change]
108
+
109
+ ## How
110
+ - [Implementation approach]
111
+
112
+ ## Testing
113
+ - [What was tested and how]
114
+
115
+ ## Not Tested
116
+ - [What still needs testing, if anything]
117
+ ```
118
+
119
+ ## Common Pitfalls
120
+
121
+ - Always rename Swift/Java classes and package IDs when creating a new plugin from a template — leftover names cause registration conflicts.
122
+ - We only use Java 21 for Android builds.
123
+ - Keep temporary files clean: delete or mark with `deleteOnExit` after use.
124
+ - `dist/` is fully regenerated on every build — never edit generated files.
125
+ - Use Bun for everything. Do not use npm or npx. Use `bunx` if you need to run a package binary.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Capgo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,291 @@
1
+ # 🔒 Capsec - Capacitor Security Scanner
2
+
3
+ [![npm version](https://badge.fury.io/js/capsec.svg)](https://www.npmjs.com/package/capsec)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Zero-config security scanner for **Capacitor** and **Ionic** apps. Detect vulnerabilities, hardcoded secrets, and security misconfigurations with a single command.
7
+
8
+ 🌐 **Website:** [capacitor-sec.dev](https://capacitor-sec.dev)
9
+
10
+ ## Features
11
+
12
+ - **🚀 Zero Configuration** - Works out of the box with any Capacitor/Ionic project
13
+ - **🔐 Local Processing** - Your code never leaves your machine
14
+ - **📱 Platform-Specific** - Android and iOS security checks
15
+ - **🔑 Secret Detection** - Detects 30+ types of API keys and secrets
16
+ - **⚡ Fast** - Scans 1000+ files in seconds
17
+ - **📊 Multiple Outputs** - CLI, JSON, and HTML reports
18
+ - **🔄 CI/CD Ready** - GitHub Actions, GitLab CI support
19
+
20
+ ## Quick Start
21
+
22
+ ```bash
23
+ # Run directly with bunx (no installation needed)
24
+ bunx capsec scan
25
+
26
+ # Or install globally
27
+ bun add -g capsec
28
+ capsec scan
29
+ ```
30
+
31
+ ## Security Rules
32
+
33
+ Capsec includes **63+ security rules** across 13 categories:
34
+
35
+ | Category | Rules | Description |
36
+ |----------|-------|-------------|
37
+ | 🔑 Secrets | 2 | API keys, tokens, credentials |
38
+ | 💾 Storage | 6 | Preferences, localStorage, SQLite |
39
+ | 🌐 Network | 8 | HTTP, SSL/TLS, WebSocket |
40
+ | ⚡ Capacitor | 10 | Config, plugins, native bridge |
41
+ | 🤖 Android | 8 | Manifest, WebView, permissions |
42
+ | 🍎 iOS | 8 | ATS, Keychain, entitlements |
43
+ | 🔐 Authentication | 6 | JWT, OAuth, biometrics |
44
+ | 🖼️ WebView | 5 | XSS, CSP, iframe security |
45
+ | 🔒 Cryptography | 4 | Algorithms, keys, IV generation |
46
+ | 📝 Logging | 2 | Sensitive data in logs |
47
+ | 🐛 Debug | 3 | Test credentials, dev URLs |
48
+
49
+ ## Usage
50
+
51
+ ### Basic Scan
52
+
53
+ ```bash
54
+ # Scan current directory
55
+ capsec scan
56
+
57
+ # Scan specific path
58
+ capsec scan ./my-capacitor-app
59
+ ```
60
+
61
+ ### Output Formats
62
+
63
+ ```bash
64
+ # CLI output (default)
65
+ capsec scan
66
+
67
+ # JSON output
68
+ capsec scan --output json --output-file report.json
69
+
70
+ # HTML report
71
+ capsec scan --output html --output-file report.html
72
+ ```
73
+
74
+ ### Filtering
75
+
76
+ ```bash
77
+ # Only critical and high severity
78
+ capsec scan --severity high
79
+
80
+ # Only specific categories
81
+ capsec scan --categories storage,secrets,network
82
+
83
+ # Exclude patterns
84
+ capsec scan --exclude "**/test/**,**/demo/**"
85
+ ```
86
+
87
+ ### CI/CD Mode
88
+
89
+ ```bash
90
+ # Exit with code 1 if high/critical issues found
91
+ capsec scan --ci
92
+ ```
93
+
94
+ ### List Rules
95
+
96
+ ```bash
97
+ # List all rules
98
+ capsec rules
99
+
100
+ # Filter by category
101
+ capsec rules --category android
102
+
103
+ # Filter by severity
104
+ capsec rules --severity critical
105
+ ```
106
+
107
+ ## CI/CD Integration
108
+
109
+ ### GitHub Actions
110
+
111
+ ```yaml
112
+ name: Security Scan
113
+
114
+ on: [push, pull_request]
115
+
116
+ jobs:
117
+ security:
118
+ runs-on: ubuntu-latest
119
+ steps:
120
+ - uses: actions/checkout@v4
121
+
122
+ - name: Setup Bun
123
+ uses: oven-sh/setup-bun@v1
124
+
125
+ - name: Run Security Scan
126
+ run: bunx capsec scan --ci
127
+ ```
128
+
129
+ ### GitLab CI
130
+
131
+ ```yaml
132
+ security-scan:
133
+ image: oven/bun:latest
134
+ script:
135
+ - bunx capsec scan --ci
136
+ only:
137
+ - merge_requests
138
+ - main
139
+ ```
140
+
141
+ ## Configuration
142
+
143
+ Create a `capsec.config.json` file:
144
+
145
+ ```json
146
+ {
147
+ "exclude": [
148
+ "**/node_modules/**",
149
+ "**/dist/**"
150
+ ],
151
+ "severity": "low",
152
+ "categories": [],
153
+ "rules": {}
154
+ }
155
+ ```
156
+
157
+ Or initialize with:
158
+
159
+ ```bash
160
+ capsec init
161
+ ```
162
+
163
+ ## Programmatic Usage
164
+
165
+ ```typescript
166
+ import { SecurityScanner } from 'capsec';
167
+
168
+ const scanner = new SecurityScanner({
169
+ path: './my-app',
170
+ severity: 'medium',
171
+ categories: ['secrets', 'network']
172
+ });
173
+
174
+ const result = await scanner.scan();
175
+ console.log(result.summary);
176
+ ```
177
+
178
+ ## Rule Categories
179
+
180
+ ### Secrets (SEC)
181
+ - **SEC001** - Hardcoded API Keys & Secrets
182
+ - **SEC002** - Exposed .env File
183
+
184
+ ### Storage (STO)
185
+ - **STO001** - Unencrypted Sensitive Data in Preferences
186
+ - **STO002** - localStorage Usage for Sensitive Data
187
+ - **STO003** - SQLite Database Without Encryption
188
+ - **STO004** - Filesystem Storage of Sensitive Data
189
+ - **STO005** - Insecure Data Caching
190
+ - **STO006** - Keychain/Keystore Not Used for Credentials
191
+
192
+ ### Network (NET)
193
+ - **NET001** - HTTP Cleartext Traffic
194
+ - **NET002** - SSL/TLS Certificate Pinning Missing
195
+ - **NET003** - Capacitor Server Cleartext Enabled
196
+ - **NET004** - Insecure WebSocket Connection
197
+ - **NET005** - CORS Wildcard Configuration
198
+ - **NET006** - Insecure Deep Link Validation
199
+ - **NET007** - Capacitor HTTP Plugin Misuse
200
+ - **NET008** - Sensitive Data in URL Parameters
201
+
202
+ ### Capacitor (CAP)
203
+ - **CAP001** - WebView Debug Mode Enabled
204
+ - **CAP002** - Insecure Plugin Configuration
205
+ - **CAP003** - Verbose Logging in Production
206
+ - **CAP004** - Insecure allowNavigation
207
+ - **CAP005** - Native Bridge Exposure
208
+ - **CAP006** - Eval Usage with User Input
209
+ - **CAP007** - Missing Root/Jailbreak Detection
210
+ - **CAP008** - Insecure Plugin Import
211
+ - **CAP009** - Live Update Security
212
+ - **CAP010** - Insecure postMessage Handler
213
+
214
+ ### Android (AND)
215
+ - **AND001** - Android Cleartext Traffic Allowed
216
+ - **AND002** - Android Debug Mode Enabled
217
+ - **AND003** - Insecure Android Permissions
218
+ - **AND004** - Android Backup Allowed
219
+ - **AND005** - Exported Components Without Permission
220
+ - **AND006** - WebView JavaScript Enabled Without Safeguards
221
+ - **AND007** - Insecure WebView addJavascriptInterface
222
+ - **AND008** - Hardcoded Signing Key
223
+
224
+ ### iOS (IOS)
225
+ - **IOS001** - App Transport Security Disabled
226
+ - **IOS002** - Insecure Keychain Access
227
+ - **IOS003** - URL Scheme Without Validation
228
+ - **IOS004** - iOS Pasteboard Sensitive Data
229
+ - **IOS005** - Insecure iOS Entitlements
230
+ - **IOS006** - Background App Refresh Data Exposure
231
+ - **IOS007** - Missing iOS Jailbreak Detection
232
+ - **IOS008** - Screenshots Not Disabled for Sensitive Screens
233
+
234
+ ### Authentication (AUTH)
235
+ - **AUTH001** - Weak JWT Validation
236
+ - **AUTH002** - Insecure Biometric Implementation
237
+ - **AUTH003** - Weak Random Number Generation
238
+ - **AUTH004** - Missing Session Timeout
239
+ - **AUTH005** - OAuth State Parameter Missing
240
+ - **AUTH006** - Hardcoded Credentials in Auth
241
+
242
+ ### WebView (WEB)
243
+ - **WEB001** - WebView JavaScript Injection
244
+ - **WEB002** - Unsafe iframe Configuration
245
+ - **WEB003** - External Script Loading
246
+ - **WEB004** - Content Security Policy Missing
247
+ - **WEB005** - Target _blank Without noopener
248
+
249
+ ### Cryptography (CRY)
250
+ - **CRY001** - Weak Cryptographic Algorithm
251
+ - **CRY002** - Hardcoded Encryption Key
252
+ - **CRY003** - Insecure Random IV Generation
253
+ - **CRY004** - Weak Password Hashing
254
+
255
+ ### Logging (LOG)
256
+ - **LOG001** - Sensitive Data in Console Logs
257
+ - **LOG002** - Console Logs in Production
258
+
259
+ ### Debug (DBG)
260
+ - **DBG001** - Debugger Statement
261
+ - **DBG002** - Test Credentials in Code
262
+ - **DBG003** - Development URL in Production
263
+
264
+ ## Contributing
265
+
266
+ Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
267
+
268
+ ## License
269
+
270
+ MIT License - see [LICENSE](LICENSE) for details.
271
+
272
+ ## Related
273
+
274
+ - [Capgo](https://capgo.app) - Live updates for Capacitor apps
275
+ - [Capacitor](https://capacitorjs.com) - Build cross-platform apps
276
+ - [Ionic](https://ionicframework.com) - Mobile UI framework
277
+
278
+ ---
279
+
280
+ Built with ❤️ by the [Capgo](https://capgo.app) team
281
+
282
+ ## Compatibility
283
+
284
+ | Plugin version | Capacitor compatibility | Maintained |
285
+ | -------------- | ----------------------- | ---------- |
286
+ | v8.\*.\* | v8.\*.\* | ✅ |
287
+ | v7.\*.\* | v7.\*.\* | On demand |
288
+ | v6.\*.\* | v6.\*.\* | ❌ |
289
+ | v5.\*.\* | v5.\*.\* | ❌ |
290
+
291
+ > **Note:** The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.