realm / realm/SwiftLint

Rule Request: UnnecessaryShellCommand

Open
#2,472 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

rule-request
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
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 use URLRequest)
  • sed/awk/gawk/nawk (Can use NSRegularExpression)
  • jq (Can use JSONSerialization)

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.