Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add git:// protocol check #10261

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cabal/src/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ checkSourceRepos rs = do
checkP
(isNothing repoLocation_)
(PackageDistInexcusable MissingLocation)
checkGitProtocol repoLocation_
checkP
( repoType_ == Just (KnownRepoType CVS)
&& isNothing repoModule_
Expand Down Expand Up @@ -722,6 +723,17 @@ checkMissingVcsInfo rs =
repoTypeDirname Monotone = ["_MTN"]
repoTypeDirname Pijul = [".pijul"]

-- git:// lacks TLS or other encryption, see
-- https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_the_cons_4
checkGitProtocol
:: Monad m
=> Maybe String -- Repository location
-> CheckM m ()
checkGitProtocol mloc =
checkP
(fmap (isPrefixOf "git://") mloc == Just True)
(PackageBuildWarning GitProtocol)

-- ------------------------------------------------------------
-- Package and distribution checks
-- ------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions Cabal/src/Distribution/PackageDescription/Check/Warning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ data CheckExplanation
| UnrecognisedSourceRepo String
| MissingType
| MissingLocation
| GitProtocol
| MissingModule
| MissingTag
| SubdirRelPath
Expand Down Expand Up @@ -355,6 +356,7 @@ data CheckExplanationID
| CIUnrecognisedSourceRepo
| CIMissingType
| CIMissingLocation
| CIGitProtocol
| CIMissingModule
| CIMissingTag
| CISubdirRelPath
Expand Down Expand Up @@ -496,6 +498,7 @@ checkExplanationId (NoLicenseFile{}) = CINoLicenseFile
checkExplanationId (UnrecognisedSourceRepo{}) = CIUnrecognisedSourceRepo
checkExplanationId (MissingType{}) = CIMissingType
checkExplanationId (MissingLocation{}) = CIMissingLocation
checkExplanationId (GitProtocol{}) = CIGitProtocol
checkExplanationId (MissingModule{}) = CIMissingModule
checkExplanationId (MissingTag{}) = CIMissingTag
checkExplanationId (SubdirRelPath{}) = CISubdirRelPath
Expand Down Expand Up @@ -642,6 +645,7 @@ ppCheckExplanationId CINoLicenseFile = "no-license-file"
ppCheckExplanationId CIUnrecognisedSourceRepo = "unrecognised-repo-type"
ppCheckExplanationId CIMissingType = "repo-no-type"
ppCheckExplanationId CIMissingLocation = "repo-no-location"
ppCheckExplanationId CIGitProtocol = "git-protocol"
ppCheckExplanationId CIMissingModule = "repo-no-module"
ppCheckExplanationId CIMissingTag = "repo-no-tag"
ppCheckExplanationId CISubdirRelPath = "repo-relative-dir"
Expand Down Expand Up @@ -964,6 +968,10 @@ ppExplanation MissingType =
"The source-repository 'type' is a required field."
ppExplanation MissingLocation =
"The source-repository 'location' is a required field."
ppExplanation GitProtocol =
"Cloning over git:// might lead to an arbitrary code execution "
++ "vulnerability. Furthermore, popular forges like GitHub do "
ulysses4ever marked this conversation as resolved.
Show resolved Hide resolved
++ "not support it. Use https:// or ssh:// instead."
ppExplanation MissingModule =
"For a CVS source-repository, the 'module' is a required field."
ppExplanation MissingTag =
Expand Down
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/Check/GitProtocol/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# cabal check
The following errors are likely to affect your build negatively:
Error: [git-protocol] Cloning over git:// might lead to an arbitrary code
execution vulnerability. Furthermore, popular forges like GitHub do not
support it. Use https:// or ssh:// instead.
Error: Hackage would reject this package.
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/Check/GitProtocol/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Test.Cabal.Prelude

main = cabalTest $ fails $ cabal "check" []
16 changes: 16 additions & 0 deletions cabal-testsuite/PackageTests/Check/GitProtocol/pkg.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cabal-version: 3.0
name: pkg
version: 0
category: example
maintainer: [email protected]
synopsis: small synopsis
description: longer description
license: GPL-3.0-only

library
exposed-modules: Foo
default-language: Haskell2010

source-repository head
type: git
location: git://www.example.org/my-repo/
12 changes: 12 additions & 0 deletions changelog.d/pr-10261
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
synopsis: Warn about git:// protocol
packages: cabal-install
prs: #10261

description: {

`cabal check` will warn about insecure git:// protocol in `source-repository`.

See [Git Book](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_the_cons_4)
for an explanation.

}
3 changes: 3 additions & 0 deletions doc/cabal-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,9 @@ A list of all warnings with their constructor:
- ``unrecognised-repo-type``: unrecognised kind of source-repository.
- ``repo-no-type``: missing ``type`` in ``source-repository``.
- ``repo-no-location``: missing ``location`` in ``source-repository``.
- ``git-protocol``: using insecure ``git://`` protocol
(`explanation <https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_the_cons_4>`__
in Git Book).
- ``repo-no-module``: missing ``module`` in ``source-repository``.
- ``repo-no-tag``: missing ``tag`` in ``source-repository``.
- ``repo-relative-dir``: ``subdir`` in ``source-repository`` must be relative.
Expand Down
Loading