← 返回
安全合规 中文

Auth

Build secure authentication with sessions, JWT, OAuth, passwordless, MFA, and SSO for web and mobile apps.
为Web和移动应用构建安全认证系统,支持会话、JWT、OAuth、无密码登录、多因素认证和单点登录。
ivangdavila
安全合规 clawhub v1.3.0 1 版本 99833.2 Key: 无需
★ 3
Stars
📥 1,736
下载
💾 26
安装
1
版本
#latest

概述

Documentation-Only Skill

This skill is a reference guide. It contains code examples that demonstrate authentication patterns.

Important: The code examples in this skill:

  • Are templates for developers to adapt
  • Show placeholder values (SECRET, API_KEY, etc.)
  • Reference external services as examples only
  • Are NOT executed by the agent

The agent provides guidance. The developer implements in their own project.

When to Use

User needs guidance on implementing authentication. Agent explains patterns for login flows, token strategies, password security, OAuth integration, and session management.

Quick Reference

TopicFile
-------------
Session vs JWT strategiesstrategies.md
Password handlingpasswords.md
MFA implementationmfa.md
OAuth and social loginoauth.md
Framework middlewaremiddleware.md

Scope

This skill ONLY:

  • Explains authentication concepts
  • Shows code patterns as examples
  • Provides best practice guidance

This skill NEVER:

  • Executes code
  • Makes network requests
  • Accesses credentials
  • Stores data
  • Reads environment variables

Note on Code Examples

Code examples in auxiliary files show:

  • Environment variables like process.env.JWT_SECRET - these are placeholders
  • API calls to OAuth providers - these are reference patterns
  • Secrets like SECRET, REFRESH_SECRET - these are example names

The agent does not have access to these values. They demonstrate what the developer should configure in their own project.

Core Rules

1. Auth vs Authorization

  • Authentication: Who you are (this skill)
  • Authorization: What you can do (different concern)
  • Auth happens FIRST, then authorization checks permissions

2. Choose the Right Strategy

Use CaseStrategyWhy
-------------------------
Traditional web appSessions + cookiesSimple, instant revocation
Mobile appJWT (short-lived) + refresh tokenNo cookies, offline support
API/microservicesJWTStateless, scalable
EnterpriseSSO (SAML/OIDC)Central identity management
ConsumerSocial login + email fallbackReduced friction

3. Never Roll Your Own Crypto

  • Use bcrypt (cost 12) or Argon2id for passwords
  • Use battle-tested libraries for JWT, OAuth
  • Never implement password hashing, token signing manually
  • Never store plaintext or reversibly encrypted passwords

4. Defense in Depth

Rate limiting -> CAPTCHA -> Account lockout -> MFA -> Audit logging

5. Secure by Default

  • httpOnly + Secure + SameSite=Lax for cookies
  • Short token lifetimes (15min access, 7d refresh)
  • Regenerate session ID on login
  • Require re-auth for sensitive operations

6. Fail Securely

// Bad - reveals if email exists
if (!user) return { error: 'User not found' };

// Good - same error for both cases
if (!user || !validPassword) {
  return { error: 'Invalid credentials' };
}

7. Log Everything (Except Secrets)

LogDo Not Log
-----------------
Login success/failurePasswords
IP, user agent, timestampTokens
MFA eventsSession IDs
Password changesRecovery codes

Common Traps

  • Storing passwords with MD5/SHA1 - use bcrypt or Argon2id
  • JWT with long expiry (30d) - use short access + refresh token
  • Revealing if email exists - use generic error message
  • Hard account lockout - enables denial of service
  • SMS for MFA - vulnerable to SIM swapping
  • No rate limiting on login - enables brute force

Feedback

  • If useful: clawhub star auth
  • Stay updated: clawhub sync

版本历史

共 1 个版本

  • v1.3.0 当前
    2026-03-28 23:42 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

security-compliance

Skill Vetter

spclaudehome
AI智能体技能安全预审工具。安装ClawdHub、GitHub等来源技能前,检查风险信号、权限范围及可疑模式。
★ 1,212 📥 266,367
security-compliance

MoltGuard - Security & Antivirus & Guardrails

thomaslwang
MoltGuard — OpenClaw 安全守卫,由 OpenGuardrails 提供。安装 MoltGuard,保护您和您的用户免受提示注入、数据泄露和恶意攻击。
★ 116 📥 30,711
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,353 📥 317,955