Rule Request: UnnecessaryShellCommand
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
New rule request
As an engineer, I want to be warned early when my Swift code is trying to shell out for things that Swift libraries already provide, such as:
curl/wget(Can probably useURLRequest)sed/awk/gawk/nawk(Can useNSRegularExpression)jq(Can useJSONSerialization)
This rule would encourage more performant applications, remove dependencies on unnecessary software components, reduce attack surfaces, and increase cross-platform support, by avoiding relying on platform-specific shell command syntax.
Example triggers:
- Supplying a Process object with a launchPath ending with
curl,wget,sed,awk,jq,jq.exe, etc.
Example non-triggers:
- Supplying a Process object with an argument of
curl,wget,sed,awk,jq,jq.exe, etc.
This rule should contain a limited number of common shell commands, such as those listed above. We can add more over time. Configuration for this rule should be able to customize which of these command patterns is relevant to the user's Swift project.
As a security concern, this rule can reasonably become a default rule, as shelling out introduces additional security risks, including shell injections, compared to sticking to pure Swift code.
I would be happy to see this rule be included in Swift's available suite of checks, and if we find we're happy to apply it in a lot of places, then we can always turn it on by default later.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating SwiftLint's rule implementations and the handling of Process objects, especially launchPath. Define how the rule should distinguish a matching executable path from matching arguments, then review the requested command list, customization, default status, and trigger and non-trigger examples as the acceptance criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100