{"id":13880162,"url":"https://github.com/envato/safe_shell","last_synced_at":"2025-04-06T02:11:11.423Z","repository":{"id":56894153,"uuid":"1060895","full_name":"envato/safe_shell","owner":"envato","description":"Safely execute shell commands and get their output.","archived":false,"fork":false,"pushed_at":"2023-01-16T19:52:47.000Z","size":25,"stargazers_count":76,"open_issues_count":0,"forks_count":9,"subscribers_count":94,"default_branch":"master","last_synced_at":"2025-03-30T01:11:15.281Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/envato.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":"2010-11-08T04:42:21.000Z","updated_at":"2024-12-27T03:30:34.000Z","dependencies_parsed_at":"2023-02-10T06:01:24.841Z","dependency_job_id":null,"html_url":"https://github.com/envato/safe_shell","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Fsafe_shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Fsafe_shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Fsafe_shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envato%2Fsafe_shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/envato","download_url":"https://codeload.github.com/envato/safe_shell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247423515,"owners_count":20936626,"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":[],"created_at":"2024-08-06T08:02:49.640Z","updated_at":"2025-04-06T02:11:11.401Z","avatar_url":"https://github.com/envato.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# SafeShell\n\nSafeShell lets you execute shell commands and get the resulting output, but without the security problems of Ruby's backtick operator.\n\n## Usage\n\nInstall gem:\n\n```sh\ngem install safe_shell\n```\n\nUse gem:\n\n```ruby\nrequire 'safe_shell'\nSafeShell.execute(\"echo\", \"Hello, world!\")\n```\n\nSafeShell sets the $? operator to the process status, in the same manner as the backtick operator.\n\n```ruby\n# Send stdout and stderr to files:\nSafeShell.execute(\"echo\", \"Hello, world!\", :stdout =\u003e \"output.txt\", :stderr =\u003e \"error.txt\")\n\n# Send additional environment variables:\nSafeShell.execute(\"echo\", \"Hello, world!\", :env =\u003e { 'name' =\u003e 'john', 'foo' =\u003e 'bar' })\n\n# Return true if the command exits with a zero status:\nSafeShell.execute?(\"echo\", \"Hello, world!\")\n\n# Raise an exception if the command exits with a non-zero status:\nSafeShell.execute!(\"echo\", \"Hello, world!\")\n```\n\n## Why?\n\nIf you use backticks to process a file supplied by a user, a carefully crafted filename could allow execution of an arbitrary command:\n\n```ruby\nfile = \";blah\"\n`echo #{file}`\nsh: blah: command not found\n=\u003e \"\\n\"\n```\n\nSafeShell solves this.\n\n```ruby\nSafeShell.execute(\"echo\", file)\n=\u003e \";blah\\n\"\n```\n\n## Compatibility\n\nTested with Ruby 2.0.0 or newer, but it should be happy on pretty much any Ruby version. Maybe not so much on Windows.\n\n## Test\n\n```sh\nbundle exec rake\n````\n\n## Developing\n\n* Fork the project.\n* Make your feature addition or bug fix.\n* Add tests for it. This is important so I don't break it in a\n  future version unintentionally.\n* Commit, do not mess with rakefile, version, or history.\n  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)\n* Send me a pull request. Bonus points for topic branches.\n\n## Status\n\nIn use on at least one big site, so should be pretty solid. There's not much to it, so I'm not expecting there'll be many releases.\n\n## Copyright\n\nCopyright (c) 2010 - 2015 Envato, Ian Leitch, \u0026 Pete Yandell. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvato%2Fsafe_shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenvato%2Fsafe_shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvato%2Fsafe_shell/lists"}