Skip to content

Conversation

hmac
Copy link
Contributor

@hmac hmac commented Mar 30, 2022

This is a port of the JS query of the same name. It looks for places in a Gemfile where a http or ftp URL is specified. The tests are written using inline expectations.

hmac added 2 commits March 30, 2022 13:39
This query looks for places in a Gemfile where URLs with insecure
protocols (HTTP or FTP) are specified.
@github-actions
Copy link
Contributor

QHelp previews:

ruby/ql/src/queries/security/cwe-300/InsecureDependencyResolution.qhelp

Dependency download using unencrypted communication channel

Using an insecure protocol like HTTP or FTP to download dependencies makes the build process vulnerable to a man-in-the-middle (MITM) attack.

This can allow attackers to inject malicious code into the downloaded dependencies, and thereby infect the build artifacts and execute arbitrary code on the machine building the artifacts.

Recommendation

Always use a secure protocol, such as HTTPS or SFTP, when downloading artifacts from an URL.

Example

The below example shows a Gemfile that specifies a gem source using the insecure HTTP protocol.

source "http://rubygems.org"

gem "my-gem-a", "1.2.3"

The fix is to change the protocol to HTTPS.

source "https://rubygems.org"

gem "my-gem-a", "1.2.3"

References

@hmac hmac added the Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish label Mar 30, 2022
@hmac hmac marked this pull request as ready for review March 30, 2022 21:51
@hmac hmac requested a review from a team as a code owner March 30, 2022 21:51
@github github deleted a comment from github-actions bot Mar 30, 2022
Copy link
Contributor

@nickrolfe nickrolfe left a comment

Choose a reason for hiding this comment

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

Very nice. I have just a few small comments.

This tests that we recognise kwargs in hashrocket style:

    gem "foo", "1.2.3", :git => "..."

as well as the modern style:

    gem "foo", "1.2.3", git: "..."
@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 2022

QHelp previews:

ruby/ql/src/queries/security/cwe-300/InsecureDependencyResolution.qhelp

Dependency download using unencrypted communication channel

Using an insecure protocol like HTTP or FTP to download dependencies makes the build process vulnerable to a man-in-the-middle (MITM) attack.

This can allow attackers to inject malicious code into the downloaded dependencies, and thereby infect the build artifacts and execute arbitrary code on the machine building the artifacts.

Recommendation

Always use a secure protocol, such as HTTPS or SFTP, when downloading artifacts from an URL.

Example

The below example shows a Gemfile that specifies a gem source using the insecure HTTP protocol.

source "http://rubygems.org"

gem "my-gem-a", "1.2.3"

The fix is to change the protocol to HTTPS.

source "https://rubygems.org"

gem "my-gem-a", "1.2.3"

References

hmac and others added 2 commits April 1, 2022 15:35
Only look at the first component of strings for the prefix.

Co-authored-by: Nick Rolfe <nickrolfe@github.com>
Co-authored-by: Nick Rolfe <nickrolfe@github.com>
@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 2022

QHelp previews:

ruby/ql/src/queries/security/cwe-300/InsecureDependencyResolution.qhelp

Dependency download using unencrypted communication channel

Using an insecure protocol like HTTP or FTP to download dependencies makes the build process vulnerable to a man-in-the-middle (MITM) attack.

This can allow attackers to inject malicious code into the downloaded dependencies, and thereby infect the build artifacts and execute arbitrary code on the machine building the artifacts.

Recommendation

Always use a secure protocol, such as HTTPS or SFTP, when downloading artifacts from a URL.

Example

The below example shows a Gemfile that specifies a gem source using the insecure HTTP protocol.

source "http://rubygems.org"

gem "my-gem-a", "1.2.3"

The fix is to change the protocol to HTTPS.

source "https://rubygems.org"

gem "my-gem-a", "1.2.3"

References

nickrolfe
nickrolfe previously approved these changes Apr 1, 2022
Copy link
Contributor

@nickrolfe nickrolfe left a comment

Choose a reason for hiding this comment

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

🚀

@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2022

QHelp previews:

ruby/ql/src/queries/security/cwe-300/InsecureDependencyResolution.qhelp

Dependency download using unencrypted communication channel

Using an insecure protocol like HTTP or FTP to download dependencies makes the build process vulnerable to a man-in-the-middle (MITM) attack.

This can allow attackers to inject malicious code into the downloaded dependencies, and thereby infect the build artifacts and execute arbitrary code on the machine building the artifacts.

Recommendation

Always use a secure protocol, such as HTTPS or SFTP, when downloading artifacts from a URL.

Example

The below example shows a Gemfile that specifies a gem source using the insecure HTTP protocol.

source "http://rubygems.org"

gem "my-gem-a", "1.2.3"

The fix is to change the protocol to HTTPS.

source "https://rubygems.org"

gem "my-gem-a", "1.2.3"

References

@hmac hmac merged commit c3f1fba into github:main Apr 14, 2022
@hmac hmac deleted the hmac/insecure-dep-resolution branch April 14, 2022 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting evaluation Do not merge yet, this PR is waiting for an evaluation to finish documentation Ruby
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants