{"id":19749300,"url":"https://github.com/sipt/faygo-security","last_synced_at":"2026-05-11T13:31:22.324Z","repository":{"id":57499558,"uuid":"87314680","full_name":"sipt/faygo-security","owner":"sipt","description":"gin security middleware","archived":false,"fork":false,"pushed_at":"2017-04-22T10:49:54.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T08:22:10.601Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sipt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-05T13:47:56.000Z","updated_at":"2019-09-08T15:47:57.000Z","dependencies_parsed_at":"2022-08-28T15:22:20.682Z","dependency_job_id":null,"html_url":"https://github.com/sipt/faygo-security","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sipt/faygo-security","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sipt%2Ffaygo-security","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sipt%2Ffaygo-security/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sipt%2Ffaygo-security/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sipt%2Ffaygo-security/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sipt","download_url":"https://codeload.github.com/sipt/faygo-security/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sipt%2Ffaygo-security/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32896716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-10T13:40:02.631Z","status":"online","status_checked_at":"2026-05-11T02:00:05.975Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T02:25:58.646Z","updated_at":"2026-05-11T13:31:22.292Z","avatar_url":"https://github.com/sipt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-security\nGin security middleware\n\n## Sign\n### 介绍\n用于验证接口请求完整性，对请求的所有KV（除媒体文件）以及时间戳`timestamp`和随机字符串`nonce`，进行大小写排序，用`\u0026`、`=`相连，最后连接上`key=secret`,进行`MD5`。服务端对此进行验证。\n### 使用\nSign需要实现`ISignProvider`, `GetClientSecret`通过`clientID`来获取`ClientInfo`\n``` go\n//ISignProvider sign provider\ntype ISignProvider interface {\n\t//GetClientSecret get client secret by clientID.\n\tGetClientSecret(clientID string) (*ClientInfo, error)\n}\n```\n`CheckSign`用于获验证签名是否正确，`Sign`用于生成签名\nexample\n``` go\n//GetClientSecret get client secret by clientID.\nfunc (SignProviderImpl) GetClientSecret(clientID string) (*sign.ClientInfo, error) {\n\tconn := r.GetConn()\n\tbytes, err := redis.Bytes(conn.Do(r.GET, joinKey(clientID)))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvar clientInfo = new(sign.ClientInfo)\n\terr = proto.Unmarshal(bytes, clientInfo)\n\tif err != nil {\n\t\treturn nil, errors.New(\"clientID invalid\")\n\t}\n\treturn clientInfo, nil\n}\n```\n``` go\ncaptcha.GET(\"/\", sign.NewSignMiddleware(SignProvider), handler.CaptchaFactory)\n```\n\n## Protect\n### 介绍\n对请求中的`timestamp`和`nonce`进行验证，`timestamp`和`nonce`唯一标识一个请求，当出现请求重复时，认为是请求重放攻击，可以自行处理，如：下次发起请求时必须带有验证码。当`timestamp`超出了预设时间，如60s，就返回错误信息并且带上服务器当前时间(RFC 3339)，再次请求，超过指定次数就要求携带验证码。\n### 使用\n实现下面的接口，`IsExist`检查请求唯一性， `DealWithError`处理错误，如：`ErrorReplayAttac`请求重放,`ErrorRequestExpired`请求过期 等等。\n``` go\n//IProtectProvider protect provider\ntype IProtectProvider interface {\n\t//IsExist judge request isExist\n\tIsExist(timestamp, nonce string) (bool, error)\n\n\t//DealWithError deal with error\n\t//error : ErrorReplayAttack, ErrorTimestampFormat, ErrorRequestExpired\n\tDealWithError(ctx *gin.Context, err error)\n}\n```\n``` go\ncaptcha.GET(\"/\", protect.NewProtectMiddleware(ProtectProvider), handler.CaptchaFactory)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsipt%2Ffaygo-security","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsipt%2Ffaygo-security","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsipt%2Ffaygo-security/lists"}