{"id":16214652,"url":"https://github.com/zackeryrsmith/cval","last_synced_at":"2025-03-19T09:31:21.608Z","repository":{"id":51332420,"uuid":"459593293","full_name":"ZackeryRSmith/cval","owner":"ZackeryRSmith","description":"A layer of protection for python's eval function","archived":false,"fork":false,"pushed_at":"2023-02-22T14:06:22.000Z","size":169,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T17:50:38.040Z","etag":null,"topics":["eval","pypi-package","python","python3","security"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/cval/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZackeryRSmith.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}},"created_at":"2022-02-15T13:36:05.000Z","updated_at":"2023-02-22T02:43:09.000Z","dependencies_parsed_at":"2024-10-27T20:40:40.848Z","dependency_job_id":null,"html_url":"https://github.com/ZackeryRSmith/cval","commit_stats":{"total_commits":35,"total_committers":2,"mean_commits":17.5,"dds":"0.34285714285714286","last_synced_commit":"28525aeaab50fc42c7a0a8910d379a1547c69661"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZackeryRSmith%2Fcval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZackeryRSmith%2Fcval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZackeryRSmith%2Fcval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZackeryRSmith%2Fcval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZackeryRSmith","download_url":"https://codeload.github.com/ZackeryRSmith/cval/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243982140,"owners_count":20378605,"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","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":["eval","pypi-package","python","python3","security"],"created_at":"2024-10-10T11:11:55.803Z","updated_at":"2025-03-19T09:31:21.596Z","avatar_url":"https://github.com/ZackeryRSmith.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- TOP OF README ANCHOR --\u003e\n\u003ca name=\"top\"\u003e\u003c/a\u003e\n\n\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/ZackeryRSmith/cval\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/ZackeryRSmith/cval/main/cval.png\" alt=\"Cval logo\" width=\"155\" height=\"155\"\u003e\n  \u003c/a\u003e\n\n\u003ch3 align=\"center\"\u003eCval\u003c/h3\u003e\n\n  \u003cp align=\"center\"\u003e\n    A layer of protection for eval\n    \u003cbr /\u003e\n    \u003cb\u003e\n      \u003ca href=\"https://github.com/ZackeryRSmith/cval/#examples\"\u003eView Examples\u003c/a\u003e\n      ·\n      \u003ca href=\"https://github.com/ZackeryRSmith/cval/issues\"\u003eReport Bug\u003c/a\u003e\n    \u003c/b\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n# Installation\nI know many people don't care about the motives behind a program, so I have put the installation at the top.\n\n#### Unix and Mac\n```shell\npython3 -m pip install cval\n```\n\n#### Windows\n```powershell\npy -m pip install cval\n```\n\n## About\nA decently simple script that uses regular expression to add a layer of protection to eval. Why? Well I keep seeing *\"eval really is dangerous\"* and *\"eval is a bad practice\"*. All these statements have some validity to them, and there is almost always a better way to do what you want to acomplish. Cval tackles the *\"eval really is dangerous\"* mindset, if you must use eval for a public project use cval.\n\n## Exploiting\nI **encourage** you to break my script, report any bugs or vulnerabilities [here](https://github.com/ZackeryRSmith/cval/issues), thanks!\n\n## Examples\nThese examples are focused purely on security rather then real world practical examples.\n\n##### Disable module importing\n```python\n# :NOTE: modules is False by default, and the reason we allow function calls\n#        is to see the error given when trying to import a module.\ncval('__import__(\"os\")', calls=True, modules=False)\n```\n\n###### Output:\n```text\ncval.IllegalSource: Cval panicked due to an attempted illegal import of the module \"os\"\n```\n\n##### Allow certain modules\n```python\ncval('__import__(\"os\")', allowed_modules=[\"os\"], allowed_calls=[\"import\"])\n```\n\n##### Disable function calls\n```python\ncval('print(\"Hello, World!\")', calls=False)\n```\n\n###### Output:\n```text\ncval.IllegalSource: Cval panicked due to an illegal function call in source! Attemped call to \"print\"\n```\n\n##### Allow certain function calls\n```python\ncval('print(\"Hello, World!\")', allowed_calls=[\"print\"])\n```\n\n##### Block access to global variables\n```python\nfoo = \"bar\"\n\ndef foobar():\n    # :NOTE: `globals` doesn't need to be passed in this case\n    #        this is only done here for clarity \n    cval('print(foo)', globals=globals(), allowed_calls=[\"print\"])  # Will not be able to access \"foo\"\nfoobar()\n```\n\n###### Output:\n```text\ncval.SuspiciousSource: Cval found global variable \"foo\" in the source, killing for safety.\n```\n\n##### Allow some access to global variables\n```python\nfoo = \"bar\"\n\ndef foobar():\n    cval('print(foo)', globals=globals(), allowed_global_vars=[\"foo\"], allowed_calls=[\"print\"])\nfoobar()\n```\n\n###### Output:\n```text\nbar\n```\n\n##### Allow access to all global variables\n```python\nfoo = \"bar\"\nbar = \"foo\"\n\ndef foobar():\n    cval('print(bar+foo\")', globals=globals(), allowed_global_vars=[\"*\"], allowed_calls=[\"print\"])\nfoobar()\n```\n\n###### Output:\n```text\nfoobar\n```\n\n##### Block access local variables\n```python\ndef fizzbuzz():\n    fizz = \"buzz\"\n    cval('print(fizz)', locals=locals())  # Will not be able to access \"fizz\"\nfizzbuzz()\n```\n\n###### Output:\n```text\ncval.SuspiciousSource: Cval found local variable \"fizz\" in the source, killing for safety.\n```\n\n##### Allow some access to local variables\n```python\ndef fizzbuzz():\n    fizz = \"buzz\"\n    cval('print(fizz)', locals=locals(), allowed_local_vars=[\"fizz\"], allowed_calls=[\"print\"])\nfizzbuzz()\n```\n\n###### Output:\n```text\nbuzz\n```\n\n##### Allow access to all local variables\n```python\ndef fizzbuzz():\n    fizz = \"buzz\"\n    buzz = \"fizz\"\n    cval('print(buzz+fizz)', locals=locals(), allowed_local_vars=[\"*\"], allowed_calls=[\"print\"])\nfizzbuzz()\n```\n\n###### Output:\n```text\nfizzbuzz\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackeryrsmith%2Fcval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzackeryrsmith%2Fcval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackeryrsmith%2Fcval/lists"}