examples/plugins/security-guidance/skills/security-best-practices/SKILL.md
Security best practices and vulnerability prevention guidelines
npx skillsauth add tao12345666333/amcp security-best-practicesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
When writing code, follow these security best practices to prevent common vulnerabilities.
Always validate and sanitize user input:
# ❌ Bad - trusting user input
user_id = request.args.get('id')
query = f"SELECT * FROM users WHERE id = {user_id}"
# ✅ Good - parameterized query
user_id = request.args.get('id')
cursor.execute("SELECT * FROM users WHERE id = ?", (user_id,))
Implement secure authentication:
# ✅ Good - using bcrypt
import bcrypt
def hash_password(password: str) -> bytes:
return bcrypt.hashpw(password.encode(), bcrypt.gensalt())
def verify_password(password: str, hash: bytes) -> bool:
return bcrypt.checkpw(password.encode(), hash)
Check permissions on every request:
# ✅ Good - checking authorization
def delete_post(post_id: int, user: User):
post = get_post(post_id)
if post.author_id != user.id and not user.is_admin:
raise PermissionError("Not authorized")
delete_post_from_db(post_id)
Never hardcode secrets:
# ❌ Bad
API_KEY = "sk-1234567890abcdef"
# ✅ Good
import os
API_KEY = os.environ.get('API_KEY')
.env files for development (in .gitignore)Always use parameterized queries:
# ❌ Bad - string concatenation
cursor.execute(f"SELECT * FROM users WHERE name = '{name}'")
# ✅ Good - parameterized
cursor.execute("SELECT * FROM users WHERE name = ?", (name,))
# ✅ Good - ORM
User.query.filter_by(name=name).first()
Escape output and use Content Security Policy:
# ✅ Good - escaping in templates (Jinja2)
{{ user_input }} # Auto-escaped
# ✅ Good - explicit escaping
from markupsafe import escape
safe_output = escape(user_input)
// ❌ Bad
element.innerHTML = userInput;
// ✅ Good
element.textContent = userInput;
Implement CSRF tokens:
<form method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
...
</form>
Set security headers:
# Flask example
@app.after_request
def set_secure_headers(response):
response.headers['X-Content-Type-Options'] = 'nosniff'
response.headers['X-Frame-Options'] = 'DENY'
response.headers['X-XSS-Protection'] = '1; mode=block'
response.headers['Content-Security-Policy'] = "default-src 'self'"
return response
Don't expose sensitive information in errors:
# ❌ Bad - exposing stack trace
except Exception as e:
return {"error": str(e), "stack": traceback.format_exc()}
# ✅ Good - generic error message
except Exception as e:
logger.error(f"Error: {e}", exc_info=True)
return {"error": "An internal error occurred"}
Keep dependencies updated:
# Check for vulnerabilities
pip-audit
npm audit
snyk test
Validate file paths to prevent path traversal:
import os
# ✅ Good - validate path is within allowed directory
def safe_read(user_path: str, base_dir: str) -> str:
full_path = os.path.realpath(os.path.join(base_dir, user_path))
if not full_path.startswith(os.path.realpath(base_dir)):
raise ValueError("Path traversal attempt")
return open(full_path).read()
Log security events but not sensitive data:
# ❌ Bad - logging passwords
logger.info(f"Login attempt: user={username}, password={password}")
# ✅ Good - logging without sensitive data
logger.info(f"Login attempt: user={username}, success={success}")
| Vulnerability | Prevention | |--------------|------------| | SQL Injection | Parameterized queries | | XSS | Output encoding, CSP | | CSRF | CSRF tokens | | Path Traversal | Path validation | | Command Injection | Avoid shell=True | | Hardcoded Secrets | Environment variables | | Weak Passwords | bcrypt/argon2, complexity rules |
tools
Send and edit Telegram messages via Bot API. Use when AMCP needs to send a message, reply to a specific message, edit an existing message, or push proactive notifications (cron results, heartbeat alerts, task status). Requires AMCP_TELEGRAM_BOT_TOKEN env var.
tools
Create or update AMCP skills. Use when designing, structuring, or packaging skills with scripts, references, and assets. This skill should be used when users want to create a new skill (or update an existing skill) that extends AMCP's capabilities with specialized knowledge, workflows, or tool integrations.
tools
Backup old AMCP sessions by renaming with execution date, then clean and compact sessions and memory.
testing
Periodic heartbeat check that reads HEARTBEAT.md from the workspace and executes any tasks listed there. Use for autonomous background monitoring, periodic maintenance, and proactive task execution. Triggered by a cron schedule.