@@ -41,6 +41,20 @@ class Plugin implements PluginInterface, EventSubscriberInterface
41
41
*/
42
42
private $ versionSelector ;
43
43
44
+ /**#@+
45
+ * Constant for VBE ALLOW LIST
46
+ */
47
+ private const VBE_ALLOW_LIST = [
48
+ 'vertexinc ' ,
49
+ 'yotpo ' ,
50
+ 'klarna ' ,
51
+ 'amzn ' ,
52
+ 'dotmailer ' ,
53
+ 'braintree ' ,
54
+ 'paypal ' ,
55
+ 'gene '
56
+ ];
57
+
44
58
/**
45
59
* Initialize dependencies
46
60
* @param Version|null $version
@@ -113,33 +127,38 @@ public function packageUpdate(PackageEvent $event): void
113
127
$ privateRepoVersion = '' ;
114
128
$ publicRepoVersion = '' ;
115
129
$ privateRepoUrl = '' ;
116
- foreach ($ this ->composer ->getRepositoryManager ()->getRepositories () as $ repository ) {
117
- /** @var RepositoryInterface $repository */
118
- if ($ repository instanceof ComposerRepository) {
119
- $ found = $ this ->versionSelector ->findBestCandidate ($ this ->composer , $ packageName , $ repository );
120
- $ repoUrl = $ repository ->getRepoConfig ()['url ' ];
121
-
122
- if ($ found ) {
123
- if (strpos ($ repoUrl , self ::URL_REPO_PACKAGIST ) !== false ) {
124
- $ publicRepoVersion = $ found ->getFullPrettyVersion ();
125
- } else {
126
- $ currentPrivateRepoVersion = $ found ->getFullPrettyVersion ();
127
- //private repo version should hold highest version of package
128
- if (empty ($ privateRepoVersion ) || version_compare ($ currentPrivateRepoVersion , $ privateRepoVersion , '> ' )){
129
- $ privateRepoVersion = $ currentPrivateRepoVersion ;
130
- $ privateRepoUrl = $ repoUrl ;
130
+ list ($ namespace , $ project ) = explode ("/ " , $ packageName );
131
+ $ isPackageVBE = in_array ($ namespace , self ::VBE_ALLOW_LIST , true );
132
+
133
+ if (!$ isPackageVBE ) {
134
+
135
+ foreach ($ this ->composer ->getRepositoryManager ()->getRepositories () as $ repository ) {
136
+
137
+ /** @var RepositoryInterface $repository */
138
+ if ($ repository instanceof ComposerRepository) {
139
+ $ found = $ this ->versionSelector ->findBestCandidate ($ this ->composer , $ packageName , $ repository );
140
+ $ repoUrl = $ repository ->getRepoConfig ()['url ' ];
141
+
142
+ if ($ found ) {
143
+ if (strpos ($ repoUrl , self ::URL_REPO_PACKAGIST ) !== false ) {
144
+ $ publicRepoVersion = $ found ->getFullPrettyVersion ();
145
+ } else {
146
+ $ currentPrivateRepoVersion = $ found ->getFullPrettyVersion ();
147
+ //private repo version should hold highest version of package
148
+ if (empty ($ privateRepoVersion ) || version_compare ($ currentPrivateRepoVersion , $ privateRepoVersion , '> ' )) {
149
+ $ privateRepoVersion = $ currentPrivateRepoVersion ;
150
+ $ privateRepoUrl = $ repoUrl ;
151
+ }
131
152
}
132
153
}
133
154
}
134
155
}
135
- }
136
-
137
-
138
- if ($ privateRepoVersion && $ publicRepoVersion && (version_compare ($ publicRepoVersion , $ privateRepoVersion , '> ' ))) {
139
- $ exceptionMessage = "Higher matching version {$ publicRepoVersion } of {$ packageName } was found in public repository packagist.org
156
+ if ($ privateRepoVersion && $ publicRepoVersion && (version_compare ($ publicRepoVersion , $ privateRepoVersion , '> ' ))) {
157
+ $ exceptionMessage = "Higher matching version {$ publicRepoVersion } of {$ packageName } was found in public repository packagist.org
140
158
than {$ privateRepoVersion } in private {$ privateRepoUrl }. Public package might've been taken over by a malicious entity,
141
159
please investigate and update package requirement to match the version from the private repository " ;
142
- throw new Exception ($ exceptionMessage );
160
+ throw new Exception ($ exceptionMessage );
161
+ }
143
162
}
144
163
}
145
164
}
0 commit comments