{"id":24478519,"url":"https://github.com/clarktozer/type-graphql-csrf-middleware","last_synced_at":"2026-04-18T01:38:11.196Z","repository":{"id":57383203,"uuid":"341784298","full_name":"clarktozer/type-graphql-csrf-middleware","owner":"clarktozer","description":"TypeGraphQL middleware for handling csrf tokens","archived":false,"fork":false,"pushed_at":"2021-03-01T13:09:30.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-31T05:43:17.082Z","etag":null,"topics":["csrf","graphql","type-graphql","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clarktozer.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":"2021-02-24T05:00:35.000Z","updated_at":"2021-03-01T13:09:32.000Z","dependencies_parsed_at":"2022-09-13T23:50:29.334Z","dependency_job_id":null,"html_url":"https://github.com/clarktozer/type-graphql-csrf-middleware","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/clarktozer/type-graphql-csrf-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarktozer%2Ftype-graphql-csrf-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarktozer%2Ftype-graphql-csrf-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarktozer%2Ftype-graphql-csrf-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarktozer%2Ftype-graphql-csrf-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clarktozer","download_url":"https://codeload.github.com/clarktozer/type-graphql-csrf-middleware/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clarktozer%2Ftype-graphql-csrf-middleware/sbom","scorecard":{"id":285176,"data":{"date":"2025-08-11","repo":{"name":"github.com/clarktozer/type-graphql-csrf-middleware","commit":"7716cbe2f19dd9b9011a8c19fc1e88907d94a5ea"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.5,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/12 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/node.js.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/clarktozer/type-graphql-csrf-middleware/node.js.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/node.js.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/clarktozer/type-graphql-csrf-middleware/node.js.yml/main?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":0,"reason":"12 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-fj58-h2fr-3pp2","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-qgmg-gppg-76g5","Warn: Project is vulnerable to: GHSA-xx4c-jj58-r7x6","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T17:03:42.662Z","repository_id":57383203,"created_at":"2025-08-17T17:03:42.662Z","updated_at":"2025-08-17T17:03:42.662Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31953515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"ssl_error","status_checked_at":"2026-04-18T00:39:20.671Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["csrf","graphql","type-graphql","typescript"],"created_at":"2025-01-21T10:12:37.396Z","updated_at":"2026-04-18T01:38:11.155Z","avatar_url":"https://github.com/clarktozer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# type-graphql-csrf-middleware\n\n![CI Status](https://img.shields.io/github/workflow/status/clarktozer/type-graphql-csrf-middleware/CI)\n[![npm version](https://img.shields.io/npm/v/type-graphql-csrf-middleware.svg)](https://www.npmjs.com/package/type-graphql-csrf-middleware)\n[![types included](https://badgen.net/npm/types/type-graphql-csrf-middleware)](https://www.npmjs.com/package/type-graphql-csrf-middleware)\n\nTypeGraphQL middleware for handling csrf tokens with an express server and express-session.\n\nRequired Peer Dependencies:\n\n-   express\n-   express-session\n-   crsf\n-   cookie-parser\n-   graphql\n-   type-graphql\n\n## Installation\n\n```bash\nnpm install type-graphql-csrf-middleware\n\nyarn add type-graphql-csrf-middleware\n```\n\n```javascript\nimport { ValidAntiForgeryToken } from \"type-graphql-csrf-middleware\";\n```\n\n## Getting Started\n\nYour express server will need to add a csrf token as a cookie and a csrf secret to the session.\nBelow is an example express route middleware to add the tokens.\n\n```javascript\nconst addCsrf = (req: Request, res: Response, next: NextFunction) =\u003e {\n    const tokens = new Tokens();\n    const secret = tokens.secretSync();\n    const token = tokens.create(secret);\n\n    res.cookie(\"csrfToken\", token);\n    req.session.csrfSecret = secret;\n\n    next();\n};\n```\n\nYou will also need to add the express Request object to the GraphQL context so that it can be used by the middleware. Here is an example using Apollo Server Express.\n\n```javascript\nconst app = express();\n\nconst server = new ApolloServer({\n    schema,\n    context: ({ req, res }) =\u003e ({ req, res })\n});\n\nserver.applyMiddleware({\n    app,\n    path: \"/api\"\n});\n```\n\n## Resolver Middleware Use\n\nThe type-graphql middleware needs a cookie key and a session key that are used in your express route middleware function like the previous example in order to verify the token.\n\n```javascript\nimport { ValidAntiForgeryToken } from \"type-graphql-csrf-middleware\";\n\n@Resolver(User)\nexport class UserResolver {\n    @Query(() =\u003e User)\n    @UseMiddleware(ValidAntiForgeryToken({ cookieKey: \"csrfToken\", secretKey: \"csrfSecret\" }))\n    async me(@Ctx() ctx: MyContext): Promise\u003cUser | undefined\u003e {\n        {...}\n    }\n}\n```\n\nThe middleware can also be reusable between resolver functions.\n\n```javascript\nimport { ValidAntiForgeryToken } from \"type-graphql-csrf-middleware\";\n\nconst Authorized = ValidAntiForgeryToken({\n    cookieKey: \"csrfToken\",\n    secretKey: \"csrfSecret\",\n    message: \"Access Denied!\"\n});\n\n{...}\n\n@Resolver(User)\nexport class UserResolver {\n    @Query(() =\u003e User)\n    @UseMiddleware(Authorized)\n    async me(@Ctx() ctx: MyContext): Promise\u003cUser | undefined\u003e {\n        {...}\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarktozer%2Ftype-graphql-csrf-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclarktozer%2Ftype-graphql-csrf-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclarktozer%2Ftype-graphql-csrf-middleware/lists"}