ByteByteGo-Top 12 Tips for API Security- API安全的12大技巧

原文链接 https://blog.bytebytego.com/i/138541852/top-tips-for-api-security

What is an API key? - 什么是API Key-优快云博客

WebAuthn(Web Authentication API) 是什么?-优快云博客

B站搜“Top 12 Tips For API Security”有视频版本。

12 tips for api sec

目录

1,使用 HTTPS

2,使用 OAuth2 - (Industry Standard Authorization Protocol行业标准授权协议)

3,使用WebAuthn 

4,分配不同的操作权限给 API Keys (Use Leveled API Keys)

5,使用授权 (Authorization)

6,限流 Rate Limiting

7,分版本 API Versioning

8,白名单 Whitelisting

9,去这个网站看风险 Check OWASP API Security Risks

10,使用 API Gateway

11,Error Handling

12,输入校验 Input Validation​编辑


1,使用 HTTPS

加密传输协议,防止窃听(eavesdropping)和中间人攻击(man-in-the-middle)等。

保护敏感信息 (如 API Key, Session Token, User Data )被窥视(prying eyes)。 

 What is an API key? - 什么是API Key-优快云博客

2,使用 OAuth2 - (Industry Standard Authorization Protocol行业标准授权协议)

不直接共享凭据(credentials)。

 允许用户授权第三方应用程序对资源访问进行限制。

一个典型的 OAuth2 流程如下图所示。

1,【Authorize Service】客户端程序(如Mobile App)通过将用户重定向到授权服务器(Authorization Server, 例如Google / Facebook)初始化流程。

2,【Request Permission】用户通过授权服务器(Authorization Server)进行身份验证(Authenticate),(其实就是登录)。

3,【Request Approved】用户同意授权客户端程序(Mobile App)访问特定的资源 。

4,【Permission Granted】授权服务器(Authorization Server)告诉客户端程序(如Mobile App)用户同意了,你可以申请access token了。

5,【Get Access Token】客户端程序(如Mobile App)发起token申请。

6,【Access Token】授权服务器(Authorization Server)返回token。

7,【Request Data】客户端程序(Mobile App)代表用户使用token请求资源服务器(Resource Server)。

8,【Data】资源服务器(Resource Server)验证token,返回数据。

 再来看一个具体的例子,创建一个Travel App需要访问Google Calendar查看用户是否有空。(具体步骤同上图。)整个过程Travel App不需要存储用户名和密码。

1,Authorize calendar access  

2,Request permission

3,Request approved

4,Permission granted

5,Get access token

6,Access token(to Travel App)

7,Access token (access Resource)

3,使用WebAuthn 

  

WebAuthn(Web Authentication API) 是什么?-优快云博客

4,分配不同的操作权限给 API Keys (Use Leveled API Keys)

What is an API key? - 什么是API Key-优快云博客

5,使用授权 (Authorization)

针对不同的用户分配不同的权限,即使用户通过了认证(Authentication-【authentic】),但只能访问被授权(Authorization-【authorize】)的资源。

常见的模式是Role-based Access Control (aka RBAC)。不同的客户端指定不同的角色(Role)。

6,限流 Rate Limiting

7,分版本 API Versioning

8,白名单 Whitelisting

9,去这个网站看风险 Check OWASP API Security Risks

OWASP API Security Project | OWASP Foundation

10,使用 API Gateway

11,Error Handling

 不要打印stack trace 在生产环境,

12,输入校验 Input Validation

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值