mapbox-token-security by mapbox/mapbox-agent-skills
npx skills add https://github.com/mapbox/mapbox-agent-skills --skill mapbox-token-security此技能提供安全专业知识,用于安全有效地管理 Mapbox 访问令牌。
特性:
使用场景:
允许的作用域:
styles:tiles - 显示样式瓦片(栅格)styles:read - 读取样式规范fonts:read - 访问 Mapbox 字体datasets:read - 读取数据集数据vision:read - Vision API 访问广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
特性:
使用场景:
常见作用域:
styles:write - 创建/修改样式styles:list - 列出所有样式tokens:read - 查看令牌信息tokens:write - 创建/修改令牌特性:
使用场景:
始终授予所需的最小作用域:
❌ 错误做法:
// 权限过大 - 不要这样做
{
scopes: ['styles:read', 'styles:write', 'styles:list', 'styles:delete', 'tokens:read', 'tokens:write'];
}
✅ 正确做法:
// 仅授予显示地图所需的最小权限
{
scopes: ['styles:read', 'fonts:read'];
}
公共地图显示(客户端):
{
"scopes": ["styles:read", "fonts:read", "styles:tiles"],
"note": "用于地图显示的公共令牌",
"allowedUrls": ["https://myapp.com/*"]
}
样式管理(服务器端):
{
"scopes": ["styles:read", "styles:write", "styles:list"],
"note": "后端样式管理 - 密钥令牌"
}
令牌管理(服务器端):
{
"scopes": ["tokens:read", "tokens:write"],
"note": "仅用于令牌管理 - 密钥令牌"
}
只读访问:
{
"scopes": ["styles:list", "styles:read", "tokens:read"],
"note": "审计/监控 - 密钥令牌"
}
URL 限制限定了公共令牌可以在哪里使用,防止令牌暴露时被未经授权使用。
✅ 推荐模式:
https://myapp.com/* # 生产域名
https://*.myapp.com/* # 所有子域名
https://staging.myapp.com/* # 预发布环境
http://localhost:* # 本地开发
❌ 避免以下模式:
* # 无限制(不安全)
http://* # 任何 HTTP 站点(不安全)
*.com/* # 过于宽泛
为每个环境创建独立的令牌:
// 生产环境
{
note: "生产环境 - myapp.com",
scopes: ["styles:read", "fonts:read"],
allowedUrls: ["https://myapp.com/*", "https://www.myapp.com/*"]
}
// 预发布环境
{
note: "预发布环境 - staging.myapp.com",
scopes: ["styles:read", "fonts:read"],
allowedUrls: ["https://staging.myapp.com/*"]
}
// 开发环境
{
note: "开发环境 - localhost",
scopes: ["styles:read", "fonts:read"],
allowedUrls: ["http://localhost:*", "http://127.0.0.1:*"]
}
✅ 应该做:
❌ 不应该做:
示例:安全的环境变量:
# .env (切勿提交此文件)
MAPBOX_SECRET_TOKEN=sk.ey...
# .gitignore (务必包含 .env)
.env
.env.local
.env.*.local
✅ 应该做:
❌ 不应该做:
示例:安全的客户端用法:
// 带有 URL 限制的公共令牌 - 安全
const mapboxToken = 'pk.YOUR_MAPBOX_TOKEN_HERE';
// 此令牌被限制在您的域名下
// 并且只拥有 styles:read 作用域
mapboxgl.accessToken = mapboxToken;
强制轮换:
计划轮换:
零停机轮换:
紧急轮换:
需要监控的指标:
警报触发条件:
月度检查清单:
季度检查清单:
❌ 严重错误:
// 切勿这样做 - 密钥令牌在客户端代码中
const map = new mapboxgl.Map({
accessToken: 'sk.YOUR_SECRET_TOKEN_HERE' // 密钥令牌
});
✅ 正确做法:
// 客户端代码中仅使用公共令牌
const map = new mapboxgl.Map({
accessToken: 'pk.YOUR_PUBLIC_TOKEN_HERE' // 公共令牌
});
❌ 过于宽泛:
{
"scopes": ["styles:*", "tokens:*"]
}
✅ 具体限定:
{
"scopes": ["styles:read"]
}
❌ 无限制:
{
"scopes": ["styles:read"],
"allowedUrls": [] // 令牌在任何地方都有效
}
✅ 域名限制:
{
"scopes": ["styles:read"],
"allowedUrls": ["https://myapp.com/*"]
}
❌ 从不轮换:
Token created: Jan 2020
Last rotation: Never
Still in production: Yes
✅ 定期轮换:
Token created: Dec 2024
Last rotation: Dec 2024
Next rotation: Mar 2025
❌ 提交到 Git:
// config.js (提交到仓库)
export const MAPBOX_TOKEN = 'sk.YOUR_SECRET_TOKEN_HERE';
✅ 环境变量:
// config.js
export const MAPBOX_TOKEN = process.env.MAPBOX_SECRET_TOKEN;
# .env (在 .gitignore 中)
MAPBOX_SECRET_TOKEN=sk.YOUR_SECRET_TOKEN_HERE
立即行动(前 15 分钟):
调查(24 小时内): 5. 审查访问日志以了解暴露情况 6. 检查 Mapbox 控制面板中是否有未经授权的使用 7. 确定根本原因(是如何暴露的?) 8. 记录事件,包括时间线和影响
预防(1 周内): 9. 更新流程以防止再次发生 10. 实施额外的安全措施(CI 检查、密钥扫描) 11. 培训团队吸取教训 12. 更新文档,加入新的安全措施
令牌创建:
令牌管理:
监控:
事件响应:
在以下情况下调用此技能:
每周安装量
291
仓库
GitHub Stars
35
首次出现
Feb 2, 2026
安全审计
安装于
codex267
opencode266
gemini-cli265
github-copilot260
amp250
kimi-cli250
This skill provides security expertise for managing Mapbox access tokens safely and effectively.
Characteristics:
When to use:
Allowed scopes:
styles:tiles - Display style tiles (raster)styles:read - Read style specificationsfonts:read - Access Mapbox fontsdatasets:read - Read dataset datavision:read - Vision API accessCharacteristics:
When to use:
Common scopes:
styles:write - Create/modify stylesstyles:list - List all stylestokens:read - View token informationtokens:write - Create/modify tokensCharacteristics:
When to use:
Always grant the minimum scopes needed:
❌ Bad:
// Overly permissive - don't do this
{
scopes: ['styles:read', 'styles:write', 'styles:list', 'styles:delete', 'tokens:read', 'tokens:write'];
}
✅ Good:
// Only what's needed for displaying a map
{
scopes: ['styles:read', 'fonts:read'];
}
Public Map Display (client-side):
{
"scopes": ["styles:read", "fonts:read", "styles:tiles"],
"note": "Public token for map display",
"allowedUrls": ["https://myapp.com/*"]
}
Style Management (server-side):
{
"scopes": ["styles:read", "styles:write", "styles:list"],
"note": "Backend style management - SECRET TOKEN"
}
Token Administration (server-side):
{
"scopes": ["tokens:read", "tokens:write"],
"note": "Token management only - SECRET TOKEN"
}
Read-Only Access:
{
"scopes": ["styles:list", "styles:read", "tokens:read"],
"note": "Auditing/monitoring - SECRET TOKEN"
}
URL restrictions limit where a public token can be used, preventing unauthorized usage if the token is exposed.
✅ Recommended patterns:
https://myapp.com/* # Production domain
https://*.myapp.com/* # All subdomains
https://staging.myapp.com/* # Staging environment
http://localhost:* # Local development
❌ Avoid these:
* # No restriction (insecure)
http://* # Any HTTP site (insecure)
*.com/* # Too broad
Create separate tokens for each environment:
// Production
{
note: "Production - myapp.com",
scopes: ["styles:read", "fonts:read"],
allowedUrls: ["https://myapp.com/*", "https://www.myapp.com/*"]
}
// Staging
{
note: "Staging - staging.myapp.com",
scopes: ["styles:read", "fonts:read"],
allowedUrls: ["https://staging.myapp.com/*"]
}
// Development
{
note: "Development - localhost",
scopes: ["styles:read", "fonts:read"],
allowedUrls: ["http://localhost:*", "http://127.0.0.1:*"]
}
✅ DO:
❌ DON'T:
Example: Secure Environment Variable:
# .env (NEVER commit this file)
MAPBOX_SECRET_TOKEN=sk.ey...
# .gitignore (ALWAYS include .env)
.env
.env.local
.env.*.local
✅ DO:
❌ DON'T:
Example: Safe Client Usage:
// Public token with URL restrictions - SAFE
const mapboxToken = 'pk.YOUR_MAPBOX_TOKEN_HERE';
// This token is restricted to your domain
// and only has styles:read scope
mapboxgl.accessToken = mapboxToken;
Mandatory rotation:
Scheduled rotation:
Zero-downtime rotation:
Emergency rotation:
Metrics to monitor:
Alert on:
Monthly checklist:
Quarterly checklist:
❌ CRITICAL ERROR:
// NEVER DO THIS - Secret token in client code
const map = new mapboxgl.Map({
accessToken: 'sk.YOUR_SECRET_TOKEN_HERE' // SECRET TOKEN
});
✅ Correct:
// Public token only in client code
const map = new mapboxgl.Map({
accessToken: 'pk.YOUR_PUBLIC_TOKEN_HERE' // PUBLIC TOKEN
});
❌ Too broad:
{
"scopes": ["styles:*", "tokens:*"]
}
✅ Specific:
{
"scopes": ["styles:read"]
}
❌ No restrictions:
{
"scopes": ["styles:read"],
"allowedUrls": [] // Token works anywhere
}
✅ Domain restricted:
{
"scopes": ["styles:read"],
"allowedUrls": ["https://myapp.com/*"]
}
❌ Never rotated:
Token created: Jan 2020
Last rotation: Never
Still in production: Yes
✅ Regular rotation:
Token created: Dec 2024
Last rotation: Dec 2024
Next rotation: Mar 2025
❌ Committed to Git:
// config.js (committed to repo)
export const MAPBOX_TOKEN = 'sk.YOUR_SECRET_TOKEN_HERE';
✅ Environment variables:
// config.js
export const MAPBOX_TOKEN = process.env.MAPBOX_SECRET_TOKEN;
# .env (in .gitignore)
MAPBOX_SECRET_TOKEN=sk.YOUR_SECRET_TOKEN_HERE
Immediate actions (first 15 minutes):
Investigation (within 24 hours): 5. Review access logs to understand exposure 6. Check for unauthorized usage in Mapbox dashboard 7. Identify root cause (how was it exposed?) 8. Document incident with timeline and impact
Prevention (within 1 week): 9. Update procedures to prevent recurrence 10. Implement additional safeguards (CI checks, secret scanning) 11. Train team on lessons learned 12. Update documentation with new security measures
Token Creation:
Token Management:
Monitoring:
Incident Response:
Invoke this skill when:
Weekly Installs
291
Repository
GitHub Stars
35
First Seen
Feb 2, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex267
opencode266
gemini-cli265
github-copilot260
amp250
kimi-cli250
Linux云主机安全托管指南:从SSH加固到HTTPS部署
19,700 周安装