ma-agents 2.0.0 → 2.2.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 +37 -0
- package/skills/code-documentation/SKILL.md +53 -0
- package/skills/code-documentation/examples/cpp.md +29 -0
- package/skills/code-documentation/examples/csharp.md +28 -0
- package/skills/code-documentation/examples/javascript_typescript.md +28 -0
- package/skills/code-documentation/examples/python.md +57 -0
- package/skills/code-documentation/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
|
@@ -302,6 +302,43 @@ Enforces target-based, property-oriented CMake patterns (CMake 3.0+ philosophy).
|
|
|
302
302
|
|
|
303
303
|
---
|
|
304
304
|
|
|
305
|
+
### 14. Code Documentation Best Practices
|
|
306
|
+
**Directory:** `code-documentation/`
|
|
307
|
+
|
|
308
|
+
Enforces standardized file headers and method documentation across C++, C#, JS, and TS.
|
|
309
|
+
|
|
310
|
+
**Key Features:**
|
|
311
|
+
- ✅ **Standardized Headers**: Mandatory purpose, author, and version metadata.
|
|
312
|
+
- ✅ **Language Standards**: Supporting Doxygen (C++), XML (C#), and JSDoc (JS/TS).
|
|
313
|
+
- ✅ **Semantic Richness**: Mandates documenting `@param`, `@returns`, and `@throws`.
|
|
314
|
+
|
|
315
|
+
---
|
|
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
|
+
|
|
305
342
|
## Requirements
|
|
306
343
|
|
|
307
344
|
### All Skills
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Code Documentation Best Practices
|
|
2
|
+
|
|
3
|
+
This skill enforces high-quality, standardized documentation for source code files and methods. It ensures consistent metadata and clear explanations of intent across different programming languages.
|
|
4
|
+
|
|
5
|
+
## Policies
|
|
6
|
+
|
|
7
|
+
### 1. Mandatory File Headers
|
|
8
|
+
* **Rule**: Every source file must begin with a standardized header block.
|
|
9
|
+
* **Contents**:
|
|
10
|
+
- **Purpose**: A brief description of what the file contains/solves.
|
|
11
|
+
- **Author/Project**: Project name or author information.
|
|
12
|
+
- **Metadata**: Date created/modified and version if applicable.
|
|
13
|
+
|
|
14
|
+
### 2. Mandatory Method Documentation
|
|
15
|
+
* **Rule**: Every public or non-trivial internal function/method must have a documentation block immediately preceding it.
|
|
16
|
+
* **Standards**:
|
|
17
|
+
- **C++**: Use Doxygen style (`/** ... */`).
|
|
18
|
+
- **C#**: Use XML Documentation style (`/// <summary> ...`).
|
|
19
|
+
- **JS/TS**: Use JSDoc style (`/** ... */`).
|
|
20
|
+
- **Python**: Use PEP 257 Docstrings (`""" ... """`).
|
|
21
|
+
* **Required Fields**:
|
|
22
|
+
- **Summary**: Concise description of what the method does.
|
|
23
|
+
- **Parameters**: Name and purpose of each argument.
|
|
24
|
+
- **Return Value**: Description of the output.
|
|
25
|
+
- **Exceptions/Errors**: Document significant error states or exceptions thrown.
|
|
26
|
+
|
|
27
|
+
### 3. Focus on "Why" and "What"
|
|
28
|
+
* **Rule**: Do not document trivial code (e.g., `i++ // increment i`).
|
|
29
|
+
* **Action**: Document the **intent** and **usage constraints**. If the code is complex, explain the high-level logic rather than line-by-line mechanics.
|
|
30
|
+
|
|
31
|
+
### 4. Semantic Linking
|
|
32
|
+
* **Rule**: Use language-specific linking features (e.g., `@see`, `{@link}`, `<see cref=.../>`) to refer to related types or methods.
|
|
33
|
+
|
|
34
|
+
## Language Specifics
|
|
35
|
+
|
|
36
|
+
| Language | Format | Key Tags |
|
|
37
|
+
| :--- | :--- | :--- |
|
|
38
|
+
| **C++** | Doxygen | `\brief`, `\param`, `\return`, `\throw` |
|
|
39
|
+
| **C#** | XML Doc | `<summary>`, `<param>`, `<returns>`, `<exception>` |
|
|
40
|
+
| **JS/TS** | JSDoc | `@description`, `@param`, `@returns`, `@throws` |
|
|
41
|
+
| **Python** | Docstrings | `Args:`, `Returns:`, `Raises:` (Google/NumPy style) |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Example (Generic Pattern)
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
[File Header]
|
|
49
|
+
[Imports]
|
|
50
|
+
|
|
51
|
+
[Component Documentation]
|
|
52
|
+
[Implementation]
|
|
53
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# C++ Documentation (Doxygen Style)
|
|
2
|
+
|
|
3
|
+
### File Header
|
|
4
|
+
```cpp
|
|
5
|
+
/**
|
|
6
|
+
* @file DataProcessor.hpp
|
|
7
|
+
* @brief Handles high-performance transformation of raw sensor data.
|
|
8
|
+
* @author Antigravity / ma-agents
|
|
9
|
+
* @date 2026-02-22
|
|
10
|
+
* @version 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Method Documentation
|
|
15
|
+
```cpp
|
|
16
|
+
/**
|
|
17
|
+
* @brief Calculates the moving average of a dataset.
|
|
18
|
+
*
|
|
19
|
+
* This method uses a sliding window algorithm to smooth out volatility
|
|
20
|
+
* in sensor inputs.
|
|
21
|
+
*
|
|
22
|
+
* @param data A span of float values to process.
|
|
23
|
+
* @param windowSize The size of the averaging window (must be > 0).
|
|
24
|
+
* @return The calculated moving average as a float.
|
|
25
|
+
* @throw std::invalid_argument If data is empty or windowSize is invalid.
|
|
26
|
+
* @see SignalFilter
|
|
27
|
+
*/
|
|
28
|
+
float calculateMovingAverage(gsl::span<const float> data, size_t windowSize);
|
|
29
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# C# Documentation (XML Style)
|
|
2
|
+
|
|
3
|
+
### File Header
|
|
4
|
+
```csharp
|
|
5
|
+
/*
|
|
6
|
+
* File: AuthenticationService.cs
|
|
7
|
+
* Purpose: Manages user login, token validation, and multi-factor authentication.
|
|
8
|
+
* Author: Antigravity / ma-agents
|
|
9
|
+
* Date: 2026-02-22
|
|
10
|
+
*/
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Method Documentation
|
|
14
|
+
```csharp
|
|
15
|
+
/// <summary>
|
|
16
|
+
/// Validates a user's credentials against the secure identity store.
|
|
17
|
+
/// </summary>
|
|
18
|
+
/// <param name="username">The unique identifier for the user.</param>
|
|
19
|
+
/// <param name="password">The plain-text password (will be hashed internally).</param>
|
|
20
|
+
/// <returns>
|
|
21
|
+
/// An <see cref="AuthResult"/> indicating success or failure with a details message.
|
|
22
|
+
/// </returns>
|
|
23
|
+
/// <exception cref="SecurityException">Thrown if the account is locked.</exception>
|
|
24
|
+
public async Task<AuthResult> LoginAsync(string username, string password)
|
|
25
|
+
{
|
|
26
|
+
// ...
|
|
27
|
+
}
|
|
28
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# JavaScript & TypeScript Documentation (JSDoc Style)
|
|
2
|
+
|
|
3
|
+
### File Header
|
|
4
|
+
```typescript
|
|
5
|
+
/**
|
|
6
|
+
* @file api-client.ts
|
|
7
|
+
* @description Centralized HTTP client with automatic retry and error handling.
|
|
8
|
+
* @author Antigravity / ma-agents
|
|
9
|
+
* @version 1.2.0
|
|
10
|
+
*/
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Method Documentation
|
|
14
|
+
```typescript
|
|
15
|
+
/**
|
|
16
|
+
* Fetches data from a specific endpoint with optional caching.
|
|
17
|
+
*
|
|
18
|
+
* @template T The expected type of the response data.
|
|
19
|
+
* @param {string} url The target URL (must be absolute).
|
|
20
|
+
* @param {RequestOptions} [options] Optional configuration for headers and timeouts.
|
|
21
|
+
* @returns {Promise<T>} A promise that resolves to the parsed JSON response.
|
|
22
|
+
* @throws {NetworkError} If the server is unreachable.
|
|
23
|
+
* @throws {ValidationError} If the response schema does not match T.
|
|
24
|
+
*/
|
|
25
|
+
async function fetchData<T>(url: string, options?: RequestOptions): Promise<T> {
|
|
26
|
+
// ...
|
|
27
|
+
}
|
|
28
|
+
```
|
|
@@ -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
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Code Documentation Best Practices",
|
|
3
|
+
"description": "Standardize file headers and method documentation across C++, C#, JS, TS, and Python.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"author": "Antigravity",
|
|
6
|
+
"tags": [
|
|
7
|
+
"documentation",
|
|
8
|
+
"best-practices",
|
|
9
|
+
"cpp",
|
|
10
|
+
"csharp",
|
|
11
|
+
"javascript",
|
|
12
|
+
"typescript",
|
|
13
|
+
"doxygen",
|
|
14
|
+
"jsdoc"
|
|
15
|
+
],
|
|
16
|
+
"applies_when": [
|
|
17
|
+
"creating or modifying source code files",
|
|
18
|
+
"defining new functions, methods, or classes",
|
|
19
|
+
"refactoring code logic",
|
|
20
|
+
"documenting APIs"
|
|
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
|
```
|