├── LICENSE ├── README-zh.md ├── README-ko.md └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Shieldfy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README-zh.md: -------------------------------------------------------------------------------- 1 | # 开发安全的 API 所需要核对的清单 2 | 以下是当你在设计, 测试以及发布你的 API 的时候所需要核对的重要安全措施. 3 | 4 | ------------------------------------------------------------------------------ 5 | ## 身份认证 6 | - [ ] 不要使用 `Basic Auth` 使用标准的认证协议 (比如 JWT, OAuth). 7 | - [ ] 不要再造 `Authentication`, `token generating`, `password storing` 这些轮子, 使用标准的. 8 | 9 | ### JWT (JSON Web Token) 10 | - [ ] 使用随机复杂的秘钥 (`JWT Secret`) 以增加暴力破解的难度. 11 | - [ ] 不要在请求体中直接提取数据, 要对数据进行加密 (`HS256` or `RS256`). 12 | - [ ] 是 token 的过期时间尽量的短 (`TTL`, `RTTL`) . 13 | - [ ] 不要在 JWT 的请求体重存放敏感数据, 它是可破解的 [easily](https://jwt.io/#debugger-io). 14 | 15 | ### OAuth 授权或认证协议 16 | - [ ] 始终在后台验证 `redirect_uri` 只允许白名单的 url. 17 | - [ ] 每次交换令牌的时候不要加 token (不允许 `response_type=token`). 18 | - [ ] 使用 `state` 参数并填充随机的哈希数来防止跨站请求伪造(CSRF). 19 | - [ ] 对不同的应用分别定义默认的作用于和各自有效的作用域参数. 20 | 21 | ## 访问 22 | - [ ] 限制流量来防止 DDos 攻击和暴力攻击. 23 | - [ ] 在服务端使用 HTTPS 协议来防止 MITM 攻击. 24 | - [ ] 使用 `HSTS` 协议防止 SSLStrip 攻击. 25 | 26 | ## 输入 27 | - [ ] 使用与操作相符的 HTTP 操作函数 , `GET (读取)`, `POST (创建)`, `PUT (替换/更新)` and `DELETE (删除记录)`. 28 | - [ ] 在请求头中的 `content-type` 字段使用内容验证来只允许支持的格式 (比如 `application/xml` , `application/json` ...) 并在不满足条件的时候返回 `406 Not Acceptable` . 29 | - [ ] 验证 `content-type` 的发布数据和你收到的一样 (如 `application/x-www-form-urlencoded` , `multipart/form-data ,application/json` 等等... ). 30 | - [ ] 验证用户输入来避免一些普通的易受攻击缺陷 (比如 `XSS`, `SQL-注入` , `远程代码执行` 等等...). 31 | - [ ] 不要在 URL 中使用任何敏感的数据在 ( `credentials` , `Passwords`, `security tokens`, or `API keys`), 而是使用标准的认证请求头. 32 | 33 | ## 处理 34 | - [ ] 检查是否所有的终端都在身份认证之后, 以防止破坏认证体系. 35 | - [ ] 避免使用特有的资源标识符. 使用 `/me/orders` 替代 `/user/654321/orders` 36 | - [ ] 使用 `UUID` 代替自增长的 id. 37 | - [ ] 如果你正在解析 XML 文件, 确认确保外部实体是关闭的以避免`XXE`攻击. 38 | - [ ] 在文件上传中使用 CDN. 39 | - [ ] 如果你在处理大量的数据, 使用 Workers 和 Queues 来快速响应, 从而避免 HTTP 阻塞. 40 | - [ ] 不要忘了吧 DEBUG 模式关掉. 41 | 42 | ## 输出 43 | - [ ] 发送 `X-Content-Type-Options: nosniff` 头. 44 | - [ ] 发送 `X-Frame-Options: deny` 头. 45 | - [ ] 发送 `Content-Security-Policy: default-src 'none'` 头. 46 | - [ ] 在响应中强制使用 `content-type` , 如果你的类型是 `application/json` 那么你的 `content-type` 就是 `application/json`. 47 | - [ ] 不要返回敏感的数据, 如 `credentials` , `Passwords`, `security tokens`. 48 | - [ ] 在操作结束时返回恰当的状态码. (比如 `200 OK` , `400 Bad Request` , `401 Unauthorized`, `405 Method Not Allowed` 等等...). 49 | 50 | 51 | ------------------------------------------------------------------------------ 52 | 53 | # Contribution 54 | Feel free to contribute , fork -> edit -> submit pull request. For any questions drop us an email at team@shieldfy.io. 55 | -------------------------------------------------------------------------------- /README-ko.md: -------------------------------------------------------------------------------- 1 | (中文版请戳这:[中文版](https://github.com/GrayLand119/API-Security-Checklist/blob/master/README-zh.md)) 2 | 3 | # API 보안 체크리스트 4 | API를 설계하고 테스트하고 배포할 때 고려해야 할 중요한 보안 대책 체크리스트입니다. 5 | 6 | ------------------------------------------------------------------------------ 7 | ## 인증 (Authentication) 8 | - [ ] `Basic Auth`를 사용하지 말고 표준 인증방식을 사용하세요. (예로, JWT, OAuth 등) 9 | - [ ] `인증`, `토큰 생성`, `패스워드 저장`은 직접 개발하지 말고 표준을 사용하세요. 10 | 11 | ### JWT (JSON Web Token) 12 | - [ ] 무작위 대입 공격을 어렵게 하기 위해 랜덤하고 복잡한 키값 (`JWT Secret`)을 사용하세요. 13 | - [ ] 요청 페이로드에서 알고리즘을 가져오지 마세요. 알고리즘은 백엔드에서 강제로 적용하세요. (`HS256` 혹은 `RS256`) 14 | - [ ] 토큰 만료기간 (`TTL`, `RTTL`)은 되도록 짧게 설정하세요. 15 | - [ ] JWT 페이로드는 [디코딩이 쉽기](https://jwt.io/#debugger-io) 때문에 민감한 데이터는 저장하지 마세요. 16 | 17 | ### OAuth 18 | - [ ] 허용된 URL만 받기 위해서는 서버단에서 `redirect_uri`가 유효한지 항상 검증하세요. 19 | - [ ] 토큰 대신 항상 코드를 주고 받으세요. (`response_type=token`을 허용하지 마세요) 20 | - [ ] OAuth 인증 프로세스에서 CSRF를 방지하기 위해 랜덤 해쉬값을 가진 `state` 파라미터를 사용하세요. 21 | - [ ] 디폴트 스코프를 정의하고 각 애플리케이션마다 스코프 파라미터의 유효성을 검증하세요. 22 | 23 | ## 접근 (Access) 24 | - [ ] DDoS나 무작위 대입 공격을 피하려면 요청수를 제한하세요. (Throttling) 25 | - [ ] MITM (중간자 공격)을 피하려면 서버단에서 HTTPS를 사용하세요. 26 | - [ ] SSL Strip 공격을 피하려면 `HSTS` 헤더를 SSL과 함께 사용하세요. 27 | 28 | ## 입력 및 요청 (Input) 29 | - [ ] 각 요청 연산에 맞는 적절한 HTTP 메서드를 사용하세요. `GET (읽기)`, `POST (생성)`, `PUT (대체/갱신)`, `DELETE (삭제)` 30 | - [ ] 여러분이 지원하는 포맷 (예를 들어 `application/json`이나 `application/json` 등)만을 허용하기 위해서는 요청의 Accept 헤더의 `content-type`을 검증하여 매칭되는게 없을 경우엔 `406 Not Acceptable`로 응답하세요. 31 | - [ ] 요청 받은 POST 데이터의 `content-type`을 검증하세요. (예를 들어 `application/x-www-form-urlencoded`나 `multipart/form-data` 또는 `application/json` 등) 32 | - [ ] 일반적인 취약점들을 피하기 위해선 사용자 입력의 유효성을 검증하세요. (예를 들어 `XSS`, `SQL-Injection` 또는 `Remove Code Execution` 등) 33 | - [ ] URL에는 그 어떤 민감한 데이터 (`자격 인증 (crendentials)`, `패스워드`, `보안 토큰` 또는 `API 키`)도 포함하고 있어서는 안되며 이러한 것들은 표준 인증 방식의 헤더를 사용하세요. 34 | 35 | ## 서버 처리 36 | - [ ] 잘못된 인증을 피하기 위해 모든 엔드포인트가 인증 프로세스 뒤에서 보호되고 있는지 확인하세요. 37 | - [ ] 사용자의 리소스 식별자를 사용하는건 지양하세요. `/user/654321/orders` 대신 `/me/orders`를 사용하세요. 38 | - [ ] 자동 증가 (auto-increment) 식별자 대신 `UUID`를 사용하세요. 39 | - [ ] XML 파일을 파싱하고 있다면, `XXE` (XML 외부 엔티티 공격, XML external entity attack)를 피하기 위해 엔티티 파싱을 비활성화 하세요. 40 | - [ ] XML 파일을 파싱하고 있다면, 지수적 엔티티 확장 공격을 통한 빌리언 러프/XML 폭탄을 피하기 위해 엔티티 확장을 비활성화 하세요. 41 | - [ ] 파일 업로드에는 CDN을 사용하세요. 42 | - [ ] 거대한 양의 데이터를 다루고 있다면, HTTP 블로킹을 피하고 응답을 빠르게 반환하기 위해 워커나 큐를 사용하세요. 43 | - [ ] 디버그 모드를 꺼놓는일은 절대 잊지 마세요. 44 | 45 | ## 반환 및 응답 46 | - [ ] `X-Content-Type-Options: nosniff` 헤더를 반환하세요. 47 | - [ ] `X-Frame-Options: deny` 헤더를 반환하세요. 48 | - [ ] `Content-Security-Policy: default-src 'none'` 헤더를 반환하세요. 49 | - [ ] `X-Powered-By`, `Server`, `X-AspNet-Version` 등의 디지털 지문 (fingerprinting) 성격의 헤더는 제거하세요. 50 | - [ ] 응답에 `content-type`을 강제하세요. 만약 `application/json` 데이터를 반환하고 있다면 응답의 `content-type`은 `application/json`입니다. 51 | - [ ] `자격 인증 (crendentials)`, `패스워드`, `보안 토큰`과 같은 민감한 데이터는 반환하지 마세요. 52 | - [ ] 각 연산에 맞는 적절한 상태 코드를 반환하세요. (예를 들어 `200 OK`, `400 Bad Request`, `401 Unauthorized`, `405 Method Not Allowed` 등) 53 | 54 | 55 | ------------------------------------------------------------------------------ 56 | 57 | # Contribution 58 | Feel free to contribute , fork -> edit -> submit pull request. For any questions drop us an email at team@shieldfy.io. 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | (中文版请戳这:[中文版](https://github.com/GrayLand119/API-Security-Checklist/blob/master/README-zh.md)) 2 | 3 | # API Security Checklist 4 | Checklist of the most important security countermeasures when designing, testing, and releasing your API. 5 | 6 | ------------------------------------------------------------------------------ 7 | ## Authentication 8 | - [ ] Don't use `Basic Auth` Use standard authentication (e.g. JWT, OAuth). 9 | - [ ] Don't reinvent the wheel in `Authentication`, `token generating`, `password storing` use the standards. 10 | 11 | ### JWT (JSON Web Token) 12 | - [ ] Use random complicated key (`JWT Secret`) to make brute forcing token very hard. 13 | - [ ] Don't extract the algorithm from the payload. Force algorithm in the backend (`HS256` or `RS256`). 14 | - [ ] Make token expiration (`TTL`, `RTTL`) as short as possible. 15 | - [ ] Don't store sensitive data in the JWT payload, it can be decoded [easily](https://jwt.io/#debugger-io). 16 | 17 | ### OAuth 18 | - [ ] Always validate `redirect_uri` on server side to allow only whitelisted URLs. 19 | - [ ] Always try to exchange for code not tokens (don't allow `response_type=token`). 20 | - [ ] Use `state` parameter with a random hash to prevent CSRF on OAuth authentication process. 21 | - [ ] Define default scope, and validate scope parameter for each application. 22 | 23 | ## Access 24 | - [ ] Limit requests (Throttling) to avoid DDoS / Bruteforce attacks. 25 | - [ ] Use HTTPS on server side to avoid MITM (Man In The Middle Attack). 26 | - [ ] Use `HSTS` header with SSL to avoid SSL Strip attack. 27 | 28 | ## Input 29 | - [ ] Use proper HTTP method according to operation , `GET (read)`, `POST (create)`, `PUT (replace/update)` and `DELETE (to delete a record)`. 30 | - [ ] Validate `content-type` on request Accept header ( Content Negotiation ) to allow only your supported format (e.g. `application/xml` , `application/json` ... etc) and respond with `406 Not Acceptable` response if not matched. 31 | - [ ] Validate `content-type` of posted data as you accept (e.g. `application/x-www-form-urlencoded` , `multipart/form-data ,application/json` ... etc ). 32 | - [ ] Validate User input to avoid common vulnerabilities (e.g. `XSS`, `SQL-Injection` , `Remote Code Execution` ... etc). 33 | - [ ] Don't use any sensitive data ( `credentials` , `Passwords`, `security tokens`, or `API keys`) in the URL, but use standard Authorization header. 34 | 35 | ## Processing 36 | - [ ] Check if all endpoint protected behind the authentication to avoid broken authentication. 37 | - [ ] User own resource id should be avoided. Use `/me/orders` instead of `/user/654321/orders` 38 | - [ ] Don't use auto increment id's use `UUID` instead. 39 | - [ ] If you are parsing XML files, make sure entity parsing is not enabled to avoid `XXE` (XML external entity attack). 40 | - [ ] If you are parsing XML files, make sure entity expansion is not enabled to avoid `Billion Laughs/XML bomb` via exponential entity expansion attack. 41 | - [ ] Use CDN for file uploads. 42 | - [ ] If you are dealing with huge amount of data, use Workers and Queues to return response fast to avoid HTTP Blocking. 43 | - [ ] Do not forget to turn the DEBUG mode OFF. 44 | 45 | ## Output 46 | - [ ] Send `X-Content-Type-Options: nosniff` header. 47 | - [ ] Send `X-Frame-Options: deny` header. 48 | - [ ] Send `Content-Security-Policy: default-src 'none'` header. 49 | - [ ] Remove fingerprinting headers - `X-Powered-By`, `Server`, `X-AspNet-Version` etc. 50 | - [ ] Force `content-type` for your response , if you return `application/json` then your response `content-type` is `application/json`. 51 | - [ ] Don't return sensitive data like `credentials` , `Passwords`, `security tokens`. 52 | - [ ] Return the proper status code according to the operation completed. (e.g. `200 OK` , `400 Bad Request` , `401 Unauthorized`, `405 Method Not Allowed` ... etc). 53 | 54 | 55 | ------------------------------------------------------------------------------ 56 | 57 | # Contribution 58 | Feel free to contribute , fork -> edit -> submit pull request. For any questions drop us an email at team@shieldfy.io. 59 | --------------------------------------------------------------------------------