ma-agents 2.1.0 → 2.3.0
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.
- package/package.json +1 -1
- package/skills/README.md +38 -0
- package/skills/code-documentation/SKILL.md +2 -0
- package/skills/code-documentation/examples/python.md +57 -0
- package/skills/code-documentation/skill.json +1 -1
- package/skills/js-ts-dependency-mgmt/SKILL.md +45 -0
- package/skills/js-ts-dependency-mgmt/examples/dependency_mgmt.md +60 -0
- package/skills/js-ts-dependency-mgmt/skill.json +23 -0
- package/skills/python-dependency-mgmt/SKILL.md +38 -0
- package/skills/python-dependency-mgmt/examples/dependency_mgmt.md +67 -0
- package/skills/python-dependency-mgmt/skill.json +21 -0
- package/skills/python-security-skill/SKILL.md +52 -0
- package/skills/python-security-skill/examples/security.md +56 -0
- package/skills/python-security-skill/skill.json +20 -0
- package/skills/test-accompanied-development/SKILL.md +7 -0
- package/skills/test-accompanied-development/skill.json +3 -1
- package/skills/test-generator/SKILL.md +21 -8
- package/skills/test-generator/skill.json +2 -0
package/package.json
CHANGED
package/skills/README.md
CHANGED
|
@@ -314,6 +314,44 @@ Enforces standardized file headers and method documentation across C++, C#, JS,
|
|
|
314
314
|
|
|
315
315
|
---
|
|
316
316
|
|
|
317
|
+
### 15. Python Security Best Practices
|
|
318
|
+
**Directory:** `python-security-skill/`
|
|
319
|
+
|
|
320
|
+
Enforces secure Python coding standards aligned with OWASP Top 10 2025.
|
|
321
|
+
|
|
322
|
+
**Key Features:**
|
|
323
|
+
- ✅ **Injection Prevention**: Bans `eval()`, `exec()`, and insecure shell commands.
|
|
324
|
+
- ✅ **Secure Serialization**: Mandates `json` over `pickle` for untrusted data.
|
|
325
|
+
- ✅ **Crypto Standards**: Enforces `secrets` module and modern hashing (SHA256+).
|
|
326
|
+
- ✅ **Supply Chain**: Integrated with `pip-audit` and version pinning logic.
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
### 16. Python Dependency Management
|
|
331
|
+
**Directory:** `python-dependency-mgmt/`
|
|
332
|
+
|
|
333
|
+
Standardizes Python dependency handling using `uv` and `pip` (requirements.txt).
|
|
334
|
+
|
|
335
|
+
**Key Features:**
|
|
336
|
+
- ✅ **uv Mastery**: Full support for `uv lock`, `uv sync`, and `pyproject.toml`.
|
|
337
|
+
- ✅ **Legacy Support**: Layered `requirements.txt` (pinned + hashes).
|
|
338
|
+
- ✅ **Isolation**: Enforces virtual environment discipline and `.venv` usage.
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
### 17. JS/TS Dependency Management
|
|
343
|
+
**Directory:** `js-ts-dependency-mgmt/`
|
|
344
|
+
|
|
345
|
+
Standardizes package management and security across NPM, Yarn, and PNPM.
|
|
346
|
+
|
|
347
|
+
**Key Features:**
|
|
348
|
+
- ✅ **Build Stability**: Protocols for version pinning and lockfile discipline.
|
|
349
|
+
- ✅ **Security Audit**: Mandatory `npm audit` / `yarn audit` integration.
|
|
350
|
+
- ✅ **Categorization**: Correct usage of `dependencies` vs `devDependencies`.
|
|
351
|
+
- ✅ **Hygiene**: Standardized `.npmrc` and registry security settings.
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
317
355
|
## Requirements
|
|
318
356
|
|
|
319
357
|
### All Skills
|
|
@@ -17,6 +17,7 @@ This skill enforces high-quality, standardized documentation for source code fil
|
|
|
17
17
|
- **C++**: Use Doxygen style (`/** ... */`).
|
|
18
18
|
- **C#**: Use XML Documentation style (`/// <summary> ...`).
|
|
19
19
|
- **JS/TS**: Use JSDoc style (`/** ... */`).
|
|
20
|
+
- **Python**: Use PEP 257 Docstrings (`""" ... """`).
|
|
20
21
|
* **Required Fields**:
|
|
21
22
|
- **Summary**: Concise description of what the method does.
|
|
22
23
|
- **Parameters**: Name and purpose of each argument.
|
|
@@ -37,6 +38,7 @@ This skill enforces high-quality, standardized documentation for source code fil
|
|
|
37
38
|
| **C++** | Doxygen | `\brief`, `\param`, `\return`, `\throw` |
|
|
38
39
|
| **C#** | XML Doc | `<summary>`, `<param>`, `<returns>`, `<exception>` |
|
|
39
40
|
| **JS/TS** | JSDoc | `@description`, `@param`, `@returns`, `@throws` |
|
|
41
|
+
| **Python** | Docstrings | `Args:`, `Returns:`, `Raises:` (Google/NumPy style) |
|
|
40
42
|
|
|
41
43
|
---
|
|
42
44
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Python Documentation (Google/NumPy Style)
|
|
2
|
+
|
|
3
|
+
### File Header
|
|
4
|
+
Every module should start with a docstring that provides a high-level overview.
|
|
5
|
+
|
|
6
|
+
```python
|
|
7
|
+
"""
|
|
8
|
+
data_processor.py
|
|
9
|
+
~~~~~~~~~~~~~~~~~
|
|
10
|
+
Handles high-performance transformation of raw sensor data using NumPy.
|
|
11
|
+
|
|
12
|
+
:copyright: (c) 2026 by Antigravity.
|
|
13
|
+
:license: MIT, see LICENSE for more details.
|
|
14
|
+
"""
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Method Documentation
|
|
18
|
+
Preferred style is Google or NumPy style for readability and integration with tools like Sphinx.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
def calculate_moving_average(data, window_size):
|
|
22
|
+
"""Calculates the moving average of a dataset.
|
|
23
|
+
|
|
24
|
+
This method uses a sliding window algorithm to smooth out volatility
|
|
25
|
+
in sensor inputs.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
data (list[float]): A list or array of float values to process.
|
|
29
|
+
window_size (int): The size of the averaging window (must be > 0).
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
float: The calculated moving average.
|
|
33
|
+
|
|
34
|
+
Raises:
|
|
35
|
+
ValueError: If data is empty or window_size is invalid.
|
|
36
|
+
|
|
37
|
+
Note:
|
|
38
|
+
This implementation assumes data is already cleaned.
|
|
39
|
+
"""
|
|
40
|
+
if not data or window_size <= 0:
|
|
41
|
+
raise ValueError("Invalid data or window_size")
|
|
42
|
+
# ... implementation
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Class Documentation
|
|
46
|
+
```python
|
|
47
|
+
class SignalFilter:
|
|
48
|
+
"""A collection of signal processing utilities.
|
|
49
|
+
|
|
50
|
+
Attributes:
|
|
51
|
+
sampling_rate (int): The frequency at which signals are sampled.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
def __init__(self, sampling_rate):
|
|
55
|
+
"""Initializes the SignalFilter with a specific sampling rate."""
|
|
56
|
+
self.sampling_rate = sampling_rate
|
|
57
|
+
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "Code Documentation Best Practices",
|
|
3
|
-
"description": "Standardize file headers and method documentation across C++, C#, JS, and
|
|
3
|
+
"description": "Standardize file headers and method documentation across C++, C#, JS, TS, and Python.",
|
|
4
4
|
"version": "1.0.0",
|
|
5
5
|
"author": "Antigravity",
|
|
6
6
|
"tags": [
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# JS/TS Dependency Management (NPM, Yarn, PNPM)
|
|
2
|
+
|
|
3
|
+
This skill enforces best practices for managing dependencies in the JS/TS ecosystem, focusing on build stability, supply chain security, and environment hygiene.
|
|
4
|
+
|
|
5
|
+
## Policies
|
|
6
|
+
|
|
7
|
+
### 1. Build Stability & Reproducibility
|
|
8
|
+
* **Rule**: Always use a lockfile (`package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml`) and pin versions.
|
|
9
|
+
* **Action**:
|
|
10
|
+
- Use specific versions in `package.json` (prefer `1.2.3` over `^1.2.3` for critical production apps).
|
|
11
|
+
- NEVER use `*` or `latest`.
|
|
12
|
+
- Always commit the lockfile to version control.
|
|
13
|
+
|
|
14
|
+
### 2. Supply Chain Security (OWASP A03:2025)
|
|
15
|
+
* **Rule**: Mandatory scanning for known vulnerabilities in dependencies.
|
|
16
|
+
* **Action**:
|
|
17
|
+
- Consistently run `npm audit` or `yarn audit`.
|
|
18
|
+
- Ban insecure registry URLs (use HTTPS only).
|
|
19
|
+
- Avoid Git-based dependencies (`"pkg": "git+https://..."`) unless from an internal/verified source.
|
|
20
|
+
- Be cautious of "Typosquatting"—double-check package names before installation.
|
|
21
|
+
|
|
22
|
+
### 3. Dependency Categorization
|
|
23
|
+
* **Rule**: Correctly distinguish between runtime and development dependencies.
|
|
24
|
+
* **Action**:
|
|
25
|
+
- **dependencies**: Packages needed for the app to run (e.g., `express`, `react`).
|
|
26
|
+
- **devDependencies**: Packages needed only for building/testing (e.g., `typescript`, `jest`, `eslint`).
|
|
27
|
+
- **peerDependencies**: Libraries intended to be used with other specific versions of a host package.
|
|
28
|
+
|
|
29
|
+
### 4. Registry Hygiene
|
|
30
|
+
* **Rule**: Standardize configuration via `.npmrc`.
|
|
31
|
+
* **Action**:
|
|
32
|
+
- Define `save-exact=true` if pinning is the default project policy.
|
|
33
|
+
- Set up scoped registries for private packages correctly.
|
|
34
|
+
|
|
35
|
+
### 5. Automated Updates
|
|
36
|
+
* **Rule**: Keep dependencies current while maintaining safety.
|
|
37
|
+
* **Action**: Use tools like `npm-check-updates` (ncu) to audit updates, but verify them in separate PRs/branches.
|
|
38
|
+
|
|
39
|
+
## Process Reference
|
|
40
|
+
|
|
41
|
+
| Tool | Lockfile | Installation | Audit |
|
|
42
|
+
| :--- | :--- | :--- | :--- |
|
|
43
|
+
| **NPM** | `package-lock.json` | `npm install` | `npm audit` |
|
|
44
|
+
| **Yarn** | `yarn.lock` | `yarn install` | `yarn audit` |
|
|
45
|
+
| **PNPM** | `pnpm-lock.yaml` | `pnpm install` | `pnpm audit` |
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# JS/TS Dependency Management Examples
|
|
2
|
+
|
|
3
|
+
### 1. Secure `package.json` Structure
|
|
4
|
+
**Good Pattern:**
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"name": "secure-app",
|
|
8
|
+
"version": "1.0.0",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"axios": "1.6.2", // Pinned version
|
|
11
|
+
"express": "4.18.2" // Pinned version
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "5.3.2",
|
|
15
|
+
"jest": "29.7.0",
|
|
16
|
+
"eslint": "8.54.0"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. Standardized `.npmrc`
|
|
22
|
+
```text
|
|
23
|
+
# Enforce exact version saving by default
|
|
24
|
+
save-exact=true
|
|
25
|
+
|
|
26
|
+
# Ensure every developer uses the same registry
|
|
27
|
+
registry=https://registry.npmjs.org/
|
|
28
|
+
|
|
29
|
+
# Forbid scrips for security during install if possible
|
|
30
|
+
# ignore-scripts=true
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 3. Managing Scoped/Private Packages
|
|
34
|
+
If you use a private registry (like Artifactory or GitHub Packages):
|
|
35
|
+
```text
|
|
36
|
+
@my-org:registry=https://npm.pkg.github.com
|
|
37
|
+
//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 4. Dependency Auditing Workflow
|
|
41
|
+
**Routine Check:**
|
|
42
|
+
```bash
|
|
43
|
+
# Check for vulnerabilities
|
|
44
|
+
npm audit
|
|
45
|
+
|
|
46
|
+
# Fix minor issues automatically
|
|
47
|
+
npm audit fix
|
|
48
|
+
|
|
49
|
+
# Check for outdated packages without installing
|
|
50
|
+
npx npm-check-updates
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 5. Cleaning up Node Modules
|
|
54
|
+
```bash
|
|
55
|
+
# Remove unused dependencies
|
|
56
|
+
npm prune
|
|
57
|
+
|
|
58
|
+
# Clean install (deletes node_modules and installs from lockfile)
|
|
59
|
+
npm ci
|
|
60
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "JS/TS Dependency Management",
|
|
3
|
+
"description": "Standardize package management and security across NPM, Yarn, and PNPM.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": "Antigravity",
|
|
6
|
+
"tags": [
|
|
7
|
+
"javascript",
|
|
8
|
+
"typescript",
|
|
9
|
+
"npm",
|
|
10
|
+
"yarn",
|
|
11
|
+
"pnpm",
|
|
12
|
+
"dependencies",
|
|
13
|
+
"security",
|
|
14
|
+
"best-practices"
|
|
15
|
+
],
|
|
16
|
+
"applies_when": [
|
|
17
|
+
"managing JavaScript or TypeScript project dependencies",
|
|
18
|
+
"configuring package.json, npmrc, or lockfiles",
|
|
19
|
+
"updating NPM/Yarn/PNPM packages",
|
|
20
|
+
"auditing JS/TS supply chain security"
|
|
21
|
+
],
|
|
22
|
+
"always_load": true
|
|
23
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Python Dependency Management (uv & pip)
|
|
2
|
+
|
|
3
|
+
This skill ensures consistent and reproducible Python environments using modern tools like `uv` and traditional standards like `requirements.txt`.
|
|
4
|
+
|
|
5
|
+
## Policies
|
|
6
|
+
|
|
7
|
+
### 1. Modern Workflow with `uv`
|
|
8
|
+
* **Rule**: Use `uv` for lightning-fast project management if available.
|
|
9
|
+
* **Action**:
|
|
10
|
+
- Use `uv lock` to generate `uv.lock`.
|
|
11
|
+
- Use `uv sync` to keep the environment in sync with the lockfile.
|
|
12
|
+
- Declare dependencies in `pyproject.toml`.
|
|
13
|
+
* **Rationale**: `uv` is significantly faster than `pip` and provides deterministic builds via lockfiles.
|
|
14
|
+
|
|
15
|
+
### 2. Standardized `requirements.txt`
|
|
16
|
+
* **Rule**: If not using a modern manager, use a layered and pinned `requirements.txt` structure.
|
|
17
|
+
* **Action**:
|
|
18
|
+
- **Layered**: Use `requirements.in` (top-level deps) and `requirements.txt` (fully pinned transitive deps).
|
|
19
|
+
- **Environment Split**: Separate `requirements.txt` from `dev-requirements.txt`.
|
|
20
|
+
- **Hashes**: Generate hashes for security (`--generate-hashes` via `pip-compile`).
|
|
21
|
+
|
|
22
|
+
### 3. Strict Version Pinning
|
|
23
|
+
* **Rule**: All production dependencies must be pinned to a specific version.
|
|
24
|
+
* **Action**: Use `package==1.2.3`, never `package>=1.2.3` in the final lock/txt file.
|
|
25
|
+
|
|
26
|
+
### 4. Virtual Environment Discipline
|
|
27
|
+
* **Rule**: Never install dependencies globally.
|
|
28
|
+
* **Action**:
|
|
29
|
+
- Always create a `.venv` in the project root.
|
|
30
|
+
- For `uv`, it handles this automatically with `uv venv` or implicitly via `uv run`.
|
|
31
|
+
|
|
32
|
+
### 5. Standard Build Systems (PEP 517/518)
|
|
33
|
+
* **Rule**: Use `pyproject.toml` as the source of truth for build metadata.
|
|
34
|
+
|
|
35
|
+
## Tools of Choice
|
|
36
|
+
1. **uv**: (Recommended) Fastest all-in-one manager.
|
|
37
|
+
2. **pip-tools**: For generating pinned `requirements.txt` from `.in` files.
|
|
38
|
+
3. **venv**: Core standard for isolation.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Python Dependency Management Examples
|
|
2
|
+
|
|
3
|
+
### 1. Modern Workspace with `uv`
|
|
4
|
+
**pyproject.toml:**
|
|
5
|
+
```toml
|
|
6
|
+
[project]
|
|
7
|
+
name = "my-app"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"requests==2.31.0",
|
|
11
|
+
"structlog>=24.1.0",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[tool.uv]
|
|
15
|
+
managed = true
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Commands:**
|
|
19
|
+
```bash
|
|
20
|
+
# Add a new dependency and update lockfile
|
|
21
|
+
uv add pandas
|
|
22
|
+
|
|
23
|
+
# Run a script within the isolated environment
|
|
24
|
+
uv run main.py
|
|
25
|
+
|
|
26
|
+
# Sync environment with the lockfile
|
|
27
|
+
uv sync
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. Traditional `requirements.txt` (pip-tools)
|
|
31
|
+
**requirements.in:**
|
|
32
|
+
```text
|
|
33
|
+
flask
|
|
34
|
+
psycopg2-binary
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Workflow:**
|
|
38
|
+
```bash
|
|
39
|
+
# Generate pinned requirements.txt with hashes
|
|
40
|
+
pip-compile --generate-hashes requirements.in
|
|
41
|
+
|
|
42
|
+
# Install exactly what is pinned
|
|
43
|
+
pip install -r requirements.txt
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 3. Development vs Production Deps
|
|
47
|
+
**dev-requirements.in:**
|
|
48
|
+
```text
|
|
49
|
+
-c requirements.txt
|
|
50
|
+
pytest
|
|
51
|
+
black
|
|
52
|
+
ruff
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Generate dev-requirements.txt
|
|
57
|
+
pip-compile dev-requirements.in
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 4. Virtual Environment Setup (Standard)
|
|
61
|
+
```bash
|
|
62
|
+
python -m venv .venv
|
|
63
|
+
# Linux/macOS
|
|
64
|
+
source .venv/bin/activate
|
|
65
|
+
# Windows
|
|
66
|
+
.venv\Scripts\activate
|
|
67
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Python Dependency Management",
|
|
3
|
+
"description": "Standardize Python dependency handling using uv and pip (requirements.txt).",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": "Antigravity",
|
|
6
|
+
"tags": [
|
|
7
|
+
"python",
|
|
8
|
+
"uv",
|
|
9
|
+
"pip",
|
|
10
|
+
"dependencies",
|
|
11
|
+
"packaging",
|
|
12
|
+
"best-practices"
|
|
13
|
+
],
|
|
14
|
+
"applies_when": [
|
|
15
|
+
"managing Python project dependencies",
|
|
16
|
+
"configuring Python build systems",
|
|
17
|
+
"updating requirements.txt or uv.lock",
|
|
18
|
+
"setting up Python development environments"
|
|
19
|
+
],
|
|
20
|
+
"always_load": true
|
|
21
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Python Security Best Practices (OWASP 2025 aligned)
|
|
2
|
+
|
|
3
|
+
This skill provides mandatory security guardrails for Python applications, ensuring protection against common vulnerabilities and alignment with OWASP Top 10 standards.
|
|
4
|
+
|
|
5
|
+
## Policies
|
|
6
|
+
|
|
7
|
+
### 1. Zero Insecure Function Usage
|
|
8
|
+
* **Rule**: Ban functions that allow arbitrary code execution or insecure OS commands.
|
|
9
|
+
* **Action**:
|
|
10
|
+
- NEVER use `eval()` or `exec()`.
|
|
11
|
+
- Avoid `subprocess.run(..., shell=True)`. Use lists for commands instead.
|
|
12
|
+
- Avoid `yaml.load()` without specifying a loader (use `yaml.safe_load()`).
|
|
13
|
+
|
|
14
|
+
### 2. Secure Data Serialization
|
|
15
|
+
* **Rule**: Protect against insecure deserialization.
|
|
16
|
+
* - **Action**:
|
|
17
|
+
- NEVER use `pickle` for untrusted data. Use `json` instead.
|
|
18
|
+
- Be cautious with `xml.etree.ElementTree` (vulnerable to XXE); use `defusedxml` if possible.
|
|
19
|
+
|
|
20
|
+
### 3. Injection Prevention (A05:2025)
|
|
21
|
+
* **Rule**: Use parameterized queries for all database and API interactions.
|
|
22
|
+
* **Action**:
|
|
23
|
+
- Never use f-strings or `.format()` for SQL queries.
|
|
24
|
+
- Use ORM features (Django ORM, SQLAlchemy) or parameter placeholders (`%s`, `?`).
|
|
25
|
+
|
|
26
|
+
### 4. Cryptographic Standards (A04:2025)
|
|
27
|
+
* **Rule**: Use modern, collision-resistant hashing and encryption.
|
|
28
|
+
* **Action**:
|
|
29
|
+
- Use `hashlib.sha256()` or better. Ban MD5 and SHA1.
|
|
30
|
+
- Use `secrets` module for tokens/passwords, not `random`.
|
|
31
|
+
|
|
32
|
+
### 5. Dependency Integrity (A03:2025)
|
|
33
|
+
* **Rule**: Lock dependencies and scan for known vulnerabilities.
|
|
34
|
+
* **Action**:
|
|
35
|
+
- Always commit lockfiles (`uv.lock`, `poetry.lock`, or `requirements.txt` with hashes).
|
|
36
|
+
- Periodically run `pip-audit` or `safety`.
|
|
37
|
+
|
|
38
|
+
### 6. Secure Error Handling (A10:2025)
|
|
39
|
+
* **Rule**: Do not leak sensitive information in tracebacks or logs.
|
|
40
|
+
* **Action**:
|
|
41
|
+
- Never log `pydantic` models or raw request bodies containing PII/Secrets.
|
|
42
|
+
- Use generic error messages for end-users while keeping detailed logs internally.
|
|
43
|
+
|
|
44
|
+
## Python Security Mapping (OWASP 2025)
|
|
45
|
+
|
|
46
|
+
| Category | Python Vulnerability | Secure Alternative |
|
|
47
|
+
| :--- | :--- | :--- |
|
|
48
|
+
| **A01: Access Control** | URL hijacking in `requests` | Validate redirect targets |
|
|
49
|
+
| **A02: Configuration** | Debug mode in Flask/Django | `DEBUG = False` in production |
|
|
50
|
+
| **A03: Supply Chain** | Typosquatting/Old deps | Pin versions + `pip-audit` |
|
|
51
|
+
| **A05: Injection** | `os.system()` / RAW SQL | `subprocess.run()` list / ORM |
|
|
52
|
+
| **A08: Integrity** | `pickle.load()` | `json.loads()` |
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Python Security Examples
|
|
2
|
+
|
|
3
|
+
### 1. Secure Subprocess (Avoiding Injection)
|
|
4
|
+
**Dangerous:**
|
|
5
|
+
```python
|
|
6
|
+
import os
|
|
7
|
+
def delete_file(filename):
|
|
8
|
+
os.system(f"rm -rf {filename}") # VULNERABLE to injection
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
**Secure:**
|
|
12
|
+
```python
|
|
13
|
+
import subprocess
|
|
14
|
+
def delete_file(filename):
|
|
15
|
+
# Pass as a list, shell=False by default
|
|
16
|
+
subprocess.run(["rm", "-rf", filename], check=True)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 2. Secure Serialization
|
|
20
|
+
**Dangerous:**
|
|
21
|
+
```python
|
|
22
|
+
import pickle
|
|
23
|
+
def load_user(data):
|
|
24
|
+
return pickle.loads(data) # VULNERABLE to arbitrary code execution
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Secure:**
|
|
28
|
+
```python
|
|
29
|
+
import json
|
|
30
|
+
def load_user(data):
|
|
31
|
+
return json.loads(data) # Safe for untrusted input
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 3. Preventing SQL Injection
|
|
35
|
+
**Dangerous:**
|
|
36
|
+
```python
|
|
37
|
+
cursor.execute(f"SELECT * FROM users WHERE id = '{user_id}'")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Secure:**
|
|
41
|
+
```python
|
|
42
|
+
cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,))
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 4. Secure Randomness
|
|
46
|
+
**Dangerous:**
|
|
47
|
+
```python
|
|
48
|
+
import random
|
|
49
|
+
token = str(random.random()) # Predictable
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Secure:**
|
|
53
|
+
```python
|
|
54
|
+
import secrets
|
|
55
|
+
token = secrets.token_urlsafe(32) # Cryptographically secure
|
|
56
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Python Security Best Practices",
|
|
3
|
+
"description": "Enforce secure Python coding standards following OWASP Top 10 2025.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": "Antigravity",
|
|
6
|
+
"tags": [
|
|
7
|
+
"python",
|
|
8
|
+
"security",
|
|
9
|
+
"owasp",
|
|
10
|
+
"vulnerability-prevention",
|
|
11
|
+
"best-practices"
|
|
12
|
+
],
|
|
13
|
+
"applies_when": [
|
|
14
|
+
"writing or reviewing Python code",
|
|
15
|
+
"managing Python dependencies",
|
|
16
|
+
"configuring Python application environments",
|
|
17
|
+
"handling sensitive data in Python"
|
|
18
|
+
],
|
|
19
|
+
"always_load": true
|
|
20
|
+
}
|
|
@@ -33,7 +33,14 @@ To ensure high code quality and maintainability by mandating that all public int
|
|
|
33
33
|
|
|
34
34
|
## Example Workflow
|
|
35
35
|
|
|
36
|
+
### TypeScript (Jest)
|
|
36
37
|
1. **Agent**: "I am adding a `calculateTotal` method to the `InvoiceService`. I will also create `InvoiceService.test.ts` to verify it."
|
|
37
38
|
2. **Agent**: [Writes `calculateTotal` in `InvoiceService.ts`]
|
|
38
39
|
3. **Agent**: [Writes tests in `InvoiceService.test.ts` using `test-generator` patterns]
|
|
39
40
|
4. **Agent**: "Method and tests are complete. Running tests now..."
|
|
41
|
+
|
|
42
|
+
### Python (Pytest)
|
|
43
|
+
1. **Agent**: "I am adding a `validate_user` function to `auth.py`. I will also create `tests/test_auth.py` to verify it."
|
|
44
|
+
2. **Agent**: [Writes `validate_user` in `auth.py`]
|
|
45
|
+
3. **Agent**: [Writes tests in `tests/test_auth.py` using `test-generator` patterns]
|
|
46
|
+
4. **Agent**: "Implementation and tests are ready. Running `pytest`."
|
|
@@ -35,8 +35,9 @@ Generate comprehensive unit and integration tests for code.
|
|
|
35
35
|
- Mock external dependencies
|
|
36
36
|
- Clear assertion messages
|
|
37
37
|
|
|
38
|
-
## Example
|
|
38
|
+
## Example Outputs
|
|
39
39
|
|
|
40
|
+
### JavaScript (Jest)
|
|
40
41
|
```javascript
|
|
41
42
|
describe('ComponentName', () => {
|
|
42
43
|
test('should [behavior] when [condition]', () => {
|
|
@@ -49,13 +50,25 @@ describe('ComponentName', () => {
|
|
|
49
50
|
// Assert
|
|
50
51
|
expect(result).toEqual(expectedOutput);
|
|
51
52
|
});
|
|
53
|
+
});
|
|
54
|
+
```
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
### Python (Pytest)
|
|
57
|
+
```python
|
|
58
|
+
import pytest
|
|
59
|
+
from app.module import function_under_test
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
def test_should_behavior_when_condition():
|
|
62
|
+
# Arrange
|
|
63
|
+
input_data = setup_test_data()
|
|
64
|
+
|
|
65
|
+
# Act
|
|
66
|
+
result = function_under_test(input_data)
|
|
67
|
+
|
|
68
|
+
# Assert
|
|
69
|
+
assert result == expected_output
|
|
70
|
+
|
|
71
|
+
def test_should_raise_on_invalid_input():
|
|
72
|
+
with pytest.raises(ValueError):
|
|
73
|
+
function_under_test(None)
|
|
61
74
|
```
|