go-security

go-security is a cursor rule for Cursor from wangqiqi/cursor-ai-rules. It costs 0 tokens per session (2,254 once invoked), scanned A, original, MIT.

A set of Go security rules for writing and running production software safely. Go is a programming language commonly used for services and backend systems.

In plain words
What is it for?
Use it when building Go services, especially those handling user access, tokens, dependencies, secure communication, and security event logs.
Why use it?
It helps prevent common security mistakes such as trusting unchecked input, exposing credentials, using unsafe connections, or skipping authentication and authorization.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/. Also seen: positional $N argument.

Good fit Use it when building Go services, especially those handling user access, tokens, dependencies, secure communication, and security event logs.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/wangqiqi/cursor-ai-rules/go-security
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/wangqiqi/cursor-ai-rules

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for go-security

README.md
[![agentmods](https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/go-security/github.svg)](https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/go-security)
Your own site
<a href="https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/go-security"><img src="https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/go-security/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for go-security

Your own site · 80×15
<a href="https://agentmods.dev/rules/wangqiqi/cursor-ai-rules/go-security"><img src="https://agentmods.dev/badge/rules/wangqiqi/cursor-ai-rules/go-security.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,254 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.02254
Opus 5.5 $0.00000 $0.00902
Sonnet 5.5 $0.00000 $0.00451
Haiku 4.5 $0.00000 $0.00225

Measured 3mo ago against content hash bc0eaed11006, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

go-security scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/tech/go-security.mdc · 331 lines

How it starts

The opening of the file, as written. The whole thing — 331 lines — stays where its author put it; the contents beside it link to each section on GitHub.

🔒 Go 安全实践和最佳实践

⚠️ 执行原则

MUST 遵循以下Go安全开发准则:

  • MUST 验证所有输入数据
  • NEVER 在代码中硬编码密钥和凭据
  • ALWAYS 使用HTTPS和安全通信
  • DO NOT 忽略依赖的安全漏洞
  • MUST 实施适当的认证和授权
  • ALWAYS 记录安全相关事件

JWT 认证实现

        NotBefore: jwt.NewNumericDate(time.Now()),
        Issuer:    "your-app",
    },
}

token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString(j.secretKey)

}

func (j *JWTManager) ValidateToken(tokenString string) (*Claims, error) { token, err := jwt.ParseWithClaims(tokenString, &Claims{}, func(token *jwt.Token) (interface{}, error) { if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]) } return j.secretKey, nil })

if err != nil {
    return nil, err
}

if claims, ok := token.Claims.(*Claims); ok && token.Valid {
    return claims, nil
}

return nil, errors.New("invalid token")

}


## 📊 最佳实践

### 错误处理模式
```go
// ✅ 推荐:自定义错误类型
type Error struct {
    Code    string `json:"code"`
    Message string `json:"message"`
    Details string `json:"details,omitempty"`
}

func (e *Error) Error() string {
    return fmt.Sprintf("[%s] %s", e.Code, e.Message)
}

func NewError(code, message string) *Error {
    return &Error{
        Code:    code,
        Message: message,
    }
}

// 预定义错误
var (
    ErrNotFound     = NewError("NOT_FOUND", "resource not found")
    ErrUnauthorized = NewError("UNAUTHORIZED", "unauthorized access")
    ErrValidation   = NewError("VALIDATION_ERROR", "validation failed")
)

// ✅ 推荐:错误包装和链式调用
func (r *UserRepository) GetUserByID(ctx context.Context, id int64) (*User, error) {
    if id <= 0 {
        return nil, fmt.Errorf("%w: invalid user ID %d", ErrValidation, id)
    }

    var user User
    query := `SELECT id, username, email FROM users WHERE id = $1`

    err := r.db.QueryRowContext(ctx, query, id).Scan(
        &user.ID, &user.Username, &user.Email,
    )

Read the full file on GitHub · 331 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 331 lines · 0 tokens per session scan A bc0eaed11006

Subscribe to this mod's changes

go-security is a cursor rule published in the GitHub repository wangqiqi/cursor-ai-rules (16 stars, last pushed 6mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,254 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

go-security compared with cursor rules from other repositories

go-security next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
go-securitywangqiqi/cursor-ai-rulesCursor rule166mo agoMITA0Cursor
gonavi-goSyngnat/GoNaviCursor rule2.1kyesterdayApache-2.0A0Cursor
backend0xJacky/nginx-uiCursor rule12ktodayAGPL-3.0A441Cursor
code-stylecoddy-project/coddy-agentCursor rule215yesterdayMITA366Cursor
gosupertokens/create-supertokens-appCursor rule245d agoApache-2.0A0Cursor
go-stdlib-firsttacoda/keystoneCursor rule444d agoMITA0Cursor
gozapstore/zspCursor rule194d agoMITA0Cursor