GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Swift: Add Command Injection query (CWE-078) by maikypedia · Pull Request #13726 · github/codeql

Conversation

@maikypedia

@maikypedia maikypedia commented Jul 12, 2023

Copy link
Copy Markdown
Contributor

WIP

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
maikypedia added 2 commits July 9, 2023 04:17
@maikypedia
Initial commit
e45a317
@maikypedia
Qhelp and examples
cea3477
@maikypedia
maikypedia requested a review from a team as a code owner July 12, 2023 00:16
@github-actions github-actions Bot added documentation Swift labels Jul 12, 2023
@maikypedia maikypedia changed the title WIP : Swift: Ruby: Add Command Injection query WIP : Swift: Add Command Injection query Jul 12, 2023
geoffw0
geoffw0 reviewed Jul 12, 2023
View reviewed changes

@geoffw0 geoffw0 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @maikypedia , this query looks great! You've marked it as a work-in-progress so I'll just make a few small comments for now. When you're ready we can either do a more detailed review (and add some tests) - or we can just merge your work it into an 'experimental' directory if you'd prefer us to take it from there.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

maikypedia and MrRM1982 reacted with laugh emoji
All reactions
  • 😄 2 reactions
Comment thread swift/ql/lib/codeql/swift/security/CommandInjectionExtensions.qll Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread swift/ql/lib/codeql/swift/security/CommandInjectionQuery.qll Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread swift/ql/lib/codeql/swift/security/CommandInjectionExtensions.qll Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread swift/ql/src/queries/Security/CWE-078/CommandInjection.qhelp Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread swift/ql/src/queries/Security/CWE-078/CommandInjection.qhelp Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread swift/ql/src/queries/Security/CWE-078/CommandInjection.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

maikypedia and others added 3 commits July 12, 2023 16:44
@maikypedia @geoffw0
Doc error
d7d9ffc
Co-authored-by: Geoffrey White <[email protected]>
@maikypedia
Support CommandInjectionAdditionalFlowStep and fix doc errors
c9fadd9
@maikypedia
Fix sink
3783133
@geoffw0

geoffw0 commented Jul 27, 2023

Copy link
Copy Markdown
Contributor

@maikypedia are you still working on this? Can I help with anything?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

maikypedia and others added 2 commits July 27, 2023 22:45
@maikypedia @geoffw0
Update swift/ql/src/queries/Security/CWE-078/CommandInjection.ql
d0a912f
Co-authored-by: Geoffrey White <[email protected]>
@maikypedia
Update CommandInjection.ql
d9800c7
@maikypedia

maikypedia commented Jul 27, 2023

Copy link
Copy Markdown
Contributor Author

@maikypedia are you still working on this? Can I help with anything?

Hi @geoffw0 , the query is already finished, only the tests are missing but I am not familiar with writing stubs for swift 😅

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@geoffw0

geoffw0 commented Jul 27, 2023

Copy link
Copy Markdown
Contributor

OK, please would you move the query from src/queries/Security/CWE-078 to src/experimental/Security/CWE-078 (this excludes it from the default code scanning query suite, for now). Then I can merge it, add the tests and any other necessary changes, and move it out of experimental when everything is ready.

Thanks!

PS: I can @mention you in the PR(s) I make if you want to follow along.

maikypedia reacted with laugh emoji
All reactions
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@maikypedia maikypedia changed the title WIP : Swift: Add Command Injection query Swift: Add Command Injection query Jul 27, 2023
@maikypedia maikypedia changed the title Swift: Add Command Injection query Swift: Add Command Injection query (CWE-078) Jul 27, 2023
maikypedia added 2 commits July 28, 2023 00:15
@maikypedia
Move query to experimental
2a49219
@maikypedia
90ac5b9
@maikypedia

maikypedia commented Jul 27, 2023

Copy link
Copy Markdown
Contributor Author

OK, please would you move the query from src/queries/Security/CWE-078 to src/experimental/Security/CWE-078 (this excludes it from the default code scanning query suite, for now). Then I can merge it, add the tests and any other necessary changes, and move it out of experimental when everything is ready.

Thanks!

PS: I can @mention you in the PR(s) I make if you want to follow along.

Done 😁

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Jul 28, 2023

Copy link
Copy Markdown
Contributor

QHelp previews:

swift/ql/src/experimental/Security/CWE-078/CommandInjection.qhelp

System command built from user-controlled sources

Constructing a system command with unsanitized user input is dangerous, since a malicious user may be able to craft input that executes arbitrary code.

Recommendation

If possible, use hard-coded string literals to specify the command to run. Instead of interpreting user input directly as command names, examine the input and then choose among hard-coded string literals.

If this is not possible, then add sanitization code to verify that the user input is safe before using it.

Example

The following examples execute code from user input without sanitizing it first:

var task = Process()
task.launchPath = "/bin/bash"
task.arguments = ["-c", userControlledString] // BAD

task.launch()

If user input is used to construct a command it should be checked first. This ensures that the user cannot insert characters that have special meanings.

func validateCommand(_ command: String) -> String? {
    let allowedCommands = ["ls -l", "pwd", "echo"]
    if allowedCommands.contains(command) {
        return command
    }
    return nil
}

var task = Process()
task.launchPath = "/bin/bash"
task.arguments = ["-c", validateCommand(userControlledString)] // GOOD

task.launch()

References

  • OWASP: Command Injection.
  • Common Weakness Enumeration: CWE-78.
  • Common Weakness Enumeration: CWE-88.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

geoffw0
geoffw0 approved these changes Jul 31, 2023
View reviewed changes

@geoffw0 geoffw0 left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you again for this contribution!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

maikypedia reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@geoffw0
geoffw0 merged commit e534afe into github:main Jul 31, 2023
@geoffw0 geoffw0 mentioned this pull request Nov 6, 2023
Swift: Promote the command injection query out of experimental #14701
Merged
3 tasks done
@github github deleted a comment Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@geoffw0 geoffw0 geoffw0 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

documentation Swift

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@maikypedia @geoffw0
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.