Mozilla Public License 2.0

项目介绍

anordal/shellharden 是一个托管在 GitHub 上的开源项目,主要使用 Rust 编写,采用 Mozilla Public License 2.0 许可证,目前获得 4.8k 个 Star、132 次 Fork。

仓库全名
anordal/shellharden
开源许可证
Mozilla Public License 2.0
Star 数
4.8k
Fork 数
132
未关闭 Issue
8

README 摘要

Shellharden =========== Shellharden is a syntax highlighter and a tool to semi-automate the rewriting of scripts to ShellCheck conformance, mainly focused on quoting. The default mode of operation is like cat, but with syntax highlighting in foreground colors and suggestive changes in background colors: Above: Selected portions of xdg-desktop-menu as highlighted by Shellharden. The foreground colors are syntax…

完整内容见 GitHub 原始 README 或本页 。

常见问题

shellharden 用什么语言开发?

主要使用 Rust 编写,采用 Mozilla Public License 2.0 许可证,目前有 4.8k 个 Star。

shellharden 可以免费商用吗?

仓库标注的许可证为 Mozilla Public License 2.0,商用前请先阅读仓库 LICENSE 文件确认授权范围。

如何获取 shellharden 的源码?

可以直接克隆仓库:git clone https://github.com/anordal/shellharden.git,默认分支为 master;安装与运行步骤见仓库 README。

shellharden 最近还在维护吗?

仓库最近一次更新为 7月10日,当前有 8 个未关闭 Issue;Star 数为 4.8k,可作为社区活跃度的参考。

简要分析

热度分
5115
价值分
2926
活跃状态
活跃

语言占比

Dockerfile
Rust
Shell

Release

README

Build and test status

Shellharden

Shellharden is a syntax highlighter and a tool to semi-automate the rewriting of scripts to ShellCheck conformance, mainly focused on quoting.

The default mode of operation is like cat, but with syntax highlighting in foreground colors and suggestive changes in background colors:

real-world example

Above: Selected portions of xdg-desktop-menu as highlighted by Shellharden. The foreground colors are syntax highlighting, whereas the background colors (green and red) show characters that Shellharden would have added or removed if let loose with the --transform option. Below: An artificial example that shows more tricky cases and special features.

artificial example

Why

A variable in bash is like a hand grenade – take off its quotes, and it starts ticking. Hence, rule zero of bash pitfalls: Always use quotes.

Name

Shellharden can do what Shellcheck can’t: Apply the suggested changes.

In other words, harden vulnerable shellscripts. The builtin assumption is that the script does not depend on the vulnerable behavior – the user is responsible for the code review.

Shellharden was previously known as “Naziquote”. In the right jargon, that was the best name ever, but oh so misleading and unspeakable to outsiders.

I couldn’t call it “bash cleaner” either, as that means “poo smearer” in Norwegian.

Prior art

  • Shellcheck 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).

  • I asked this SO question, 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).

Get it

Distro packages:

Packaging status

Official rust package:

cargo install shellharden

Build from source

cargo build --release

Install

mv target/release/shellharden ~/.local/bin/

Run tests

cargo test

(requires bash)

Test coverage

env RUSTFLAGS="-C instrument-coverage" LLVM_PROFILE_FILE='run-%m.profraw' cargo test
grcov . --binary-path ./target/debug/ -s . -t html -o ./coverage/
rm run-*.profraw
open coverage/src/index.html

Fuzz test

cargo install cargo-afl
cargo afl build --release
cargo afl fuzz -i moduletests/original -o /tmp/fuzz-shellharden target/release/shellharden ''

Usage advice

Don’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!

In 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.

评论

暂无评论