{"id":13478321,"url":"https://github.com/anordal/shellharden","last_synced_at":"2025-10-21T05:01:59.549Z","repository":{"id":39707384,"uuid":"79505000","full_name":"anordal/shellharden","owner":"anordal","description":"The corrective bash syntax highlighter","archived":false,"fork":false,"pushed_at":"2024-03-24T12:20:48.000Z","size":449,"stargazers_count":4538,"open_issues_count":6,"forks_count":136,"subscribers_count":48,"default_branch":"master","last_synced_at":"2024-04-24T19:12:27.025Z","etag":null,"topics":["lint","policy","syntax-highlighter"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anordal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-01-19T23:19:34.000Z","updated_at":"2024-06-08T16:23:04.218Z","dependencies_parsed_at":"2024-01-07T01:43:13.241Z","dependency_job_id":"134b7734-4373-4684-b3ea-204c35c859a8","html_url":"https://github.com/anordal/shellharden","commit_stats":{"total_commits":279,"total_committers":7,"mean_commits":"39.857142857142854","dds":0.03584229390681004,"last_synced_commit":"b8d75485fe07173dfeb2bab0715ffbb03445df5e"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anordal%2Fshellharden","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anordal%2Fshellharden/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anordal%2Fshellharden/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anordal%2Fshellharden/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anordal","download_url":"https://codeload.github.com/anordal/shellharden/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245802340,"owners_count":20674639,"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":["lint","policy","syntax-highlighter"],"created_at":"2024-07-31T16:01:55.495Z","updated_at":"2025-10-21T05:01:59.471Z","avatar_url":"https://github.com/anordal.png","language":"Rust","funding_links":[],"categories":["Rust","others","Programming Languages","Shell Script Development","Development tools","Analysis"],"sub_categories":["Linters","Reusable Things"],"readme":"\u003cimg src=\"img/logo.png\" align=\"right\"/\u003e\n\n[![Build and test status](https://github.com/anordal/shellharden/workflows/build-and-tests/badge.svg?branch=master)](https://github.com/anordal/shellharden/actions)\n\nShellharden\n===========\n\nShellharden is a syntax highlighter and a tool to semi-automate the rewriting\nof scripts to ShellCheck conformance, mainly focused on quoting.\n\nThe default mode of operation is like `cat`, but with syntax highlighting in\nforeground colors and suggestive changes in background colors:\n\n![real-world example](img/ex-realworld.png)\n\nAbove: Selected portions of `xdg-desktop-menu` as highlighted by Shellharden.\nThe foreground colors are syntax highlighting, whereas the background colors\n(green and red) show characters that Shellharden would have added or removed\nif let loose with the `--transform` option.\nBelow: An artificial example that shows more tricky cases and special features.\n\n![artificial example](img/ex-artificial.png)\n\nWhy\n---\n\nA variable in bash is like a hand grenade – take off its quotes, and it starts ticking. Hence, rule zero of [bash pitfalls][1]: Always use quotes.\n\nName\n----\n\nShellharden can do what Shellcheck can't: Apply the suggested changes.\n\nIn other words, harden vulnerable shellscripts.\nThe builtin assumption is that the script does not *depend* on the vulnerable behavior –\nthe user is responsible for the code review.\n\nShellharden was previously known as \"Naziquote\".\nIn the right jargon, that was the best name ever,\nbut oh so misleading and unspeakable to outsiders.\n\nI couldn't call it \"bash cleaner\" either, as that means \"poo smearer\" in Norwegian.\n\nPrior art\n---------\n\n* [Shellcheck][2] is a wonderful tool to *detect*, and give general advice, about vulnerable bash code. The only thing missing is something to say yes with, and *apply* those advice (assuming proper review of course).\n\n* I asked [this SO question][3], for a tool that could rewrite bash scripts with proper quoting. One answerer beat me to it. But if it was me, I would do a syntax highlighter in the same tool (as a way to see if the parser gets lost, and make the most out of the parser, because bash is like quantum mechanics – nobody really knows how it works).\n\nGet it\n------\n\nDistro packages:\n\n[![Packaging status](https://repology.org/badge/vertical-allrepos/shellharden.svg)](https://repology.org/project/shellharden/versions)\n\n[Official rust package](https://crates.io/crates/shellharden):\n\n    cargo install shellharden\n\nBuild from source\n-----------------\n\n    cargo build --release\n\n### Install\n\n    mv target/release/shellharden ~/.local/bin/\n\n### Run tests\n\n    cargo test\n\n(requires bash)\n\n### Test coverage\n\n    env RUSTFLAGS=\"-C instrument-coverage\" LLVM_PROFILE_FILE='run-%m.profraw' cargo test\n    grcov . --binary-path ./target/debug/ -s . -t html -o ./coverage/\n    rm run-*.profraw\n    open coverage/src/index.html\n\n### Fuzz test\n\n    cargo install cargo-afl\n    cargo afl build --release\n    cargo afl fuzz -i moduletests/original -o /tmp/fuzz-shellharden target/release/shellharden ''\n\nUsage advice\n------------\n\nDon't apply `--transform` blindly; code review is still necessary: A script that *relies* on unquoted behavior (implicit word splitting and glob expansion from variables and command substitutions) to work as intended will do none of that after getting the `--transform` treatment!\n\nIn that unlucky case, ask yourself whether the script has any business in doing that. All too often, it's just a product of classical shellscripting, and would be better off rewritten, such as by using arrays. Even in the opposite case, say the business logic involves word splitting; that can still be done without invoking globbing. In short: There is always a better way than the forbidden syntax (if not more explicit), but some times, a human must step in to rewrite. See how, in the accompanying [how to do things safely in bash](how_to_do_things_safely_in_bash.md).\n\n[1]: http://mywiki.wooledge.org/BashPitfalls\n[2]: https://www.shellcheck.net/\n[3]: http://stackoverflow.com/questions/41104131/tool-to-automatically-rewrite-a-bash-script-with-proper-quoting\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanordal%2Fshellharden","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanordal%2Fshellharden","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanordal%2Fshellharden/lists"}