{"id":20126693,"url":"https://github.com/cc-d/flask-simple-csrf","last_synced_at":"2025-10-13T05:46:02.595Z","repository":{"id":57430733,"uuid":"237398450","full_name":"cc-d/flask-simple-csrf","owner":"cc-d","description":"extremely barebones csrf tokens, no backend session tracking required","archived":false,"fork":false,"pushed_at":"2023-02-15T23:08:44.000Z","size":25,"stargazers_count":10,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-25T08:53:54.930Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","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/cc-d.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-31T09:29:37.000Z","updated_at":"2025-01-05T14:30:48.000Z","dependencies_parsed_at":"2025-05-06T17:41:24.713Z","dependency_job_id":"ca662b9b-dd11-405d-a435-4ff9eac62e56","html_url":"https://github.com/cc-d/flask-simple-csrf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cc-d/flask-simple-csrf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cc-d%2Fflask-simple-csrf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cc-d%2Fflask-simple-csrf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cc-d%2Fflask-simple-csrf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cc-d%2Fflask-simple-csrf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cc-d","download_url":"https://codeload.github.com/cc-d/flask-simple-csrf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cc-d%2Fflask-simple-csrf/sbom","scorecard":{"id":268807,"data":{"date":"2025-08-11","repo":{"name":"github.com/cc-d/flask-simple-csrf","commit":"8c5ca3e134c7debe381f4f21cd25d38e946fc7ed"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"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":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"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":"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":"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":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"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":"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":-1,"reason":"no workflows found","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":"Code-Review","score":0,"reason":"Found 0/14 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":"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":"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":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"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 'master'"],"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"}}]},"last_synced_at":"2025-08-17T12:50:36.852Z","repository_id":57430733,"created_at":"2025-08-17T12:50:36.853Z","updated_at":"2025-08-17T12:50:36.853Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279013708,"owners_count":26085394,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"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-13T20:17:17.855Z","updated_at":"2025-10-13T05:46:02.582Z","avatar_url":"https://github.com/cc-d.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Install\n`pip3 install flask-simple-csrf`\nor if installing from source\n```python3 setup.py install```\n\n# How to use\nThis package is intended to assign a unique CSRF string per each form submit per user session, without requiring any backend session tracking. First, you'll want to set a variable `SECRET_CSRF_KEY` in your app config to a random, complex string. Example: `SECRET_CSRF_KEY = 'wMmeltW4mhwidorQRli6Oxx9VPXldz'`\n\nSecond, you probably want to add somthing like this to the top of your code:\n\n```\nfrom flask_simple_csrf import CSRF\n\n#app.config should have an attribute that looks something like this\n#CSRF_CONFIG = {\n#    'SECRET_CSRF_KEY': 'changeme-40-50-characters-long',\n#}\n\nCSRF = CSRF(config=config.CSRF_CONFIG)\napp = CSRF.init_app(app)\n\n@app.before_request\ndef before_request():\n        if 'CSRF_TOKEN' not in session or 'USER_CSRF' not in session:\n            session['USER_CSRF'] = random_string(64)\n            session['CSRF_TOKEN'] = CSRF.create(session['USER_CSRF'])\n```\n\nEach user session should have a unique CSRF string which changes on form submit.\n\nIn the HTML templates you want to protect, add: `{{ csrf_html(session['USER_CSRF'])|safe }}`\n\nThis will create something like this: `\u003cinput type=\"hidden\" value=\"9D...\" name=\"simplecsrf\"\u003e`\n\nI'd reccommend creating a wrapper to avoid code duplciation when checking for this value. Something like:\n```\ndef require_csrf(f):\n    @wraps(f)\n    def decorated(*args, **kwargs):\n        if request.method == 'POST':\n            user_csrf = request.form.get('simplecsrf')\n\n            if CSRF.verify(user_csrf, session['CSRF_TOKEN']) is False:\n                flash('submitted csrf does not match combined server \u0026 user keys')\n                return logout()\n\n            clear_csrf_tokens()\n            flash('csrf user token and server token match', 'success')\n\n            return f(*args, **kwargs)\n        else:\n            return f(*args, **kwargs)\n    return decorated\n```\n\nThen use the @require_csrf decorator before each flask view you'd like to require the check.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcc-d%2Fflask-simple-csrf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcc-d%2Fflask-simple-csrf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcc-d%2Fflask-simple-csrf/lists"}