Skip to content

Commit

Permalink
Add security to support options (#11271)
Browse files Browse the repository at this point in the history
This support option allows projects to specify a URL to the project's
vulnerability disclosure policy (VDP).
  • Loading branch information
ramsey committed Mar 10, 2023
1 parent d1ab125 commit cd137ee
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
},
"support": {
"issues": "https://github.com/composer/composer/issues",
"irc": "ircs://irc.libera.chat:6697/composer"
"irc": "ircs://irc.libera.chat:6697/composer",
"security": "https://github.com/composer/composer/security/policy"
}
}
1 change: 1 addition & 0 deletions doc/04-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ Support information includes the following:
* **docs:** URL to the documentation.
* **rss:** URL to the RSS feed.
* **chat:** URL to the chat channel.
* **security:** URL to the vulnerability disclosure policy (VDP).

An example:

Expand Down
5 changes: 5 additions & 0 deletions res/composer-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@
"type": "string",
"description": "URL to the RSS feed.",
"format": "uri"
},
"security": {
"type": "string",
"description": "URL to the vulnerability disclosure policy (VDP).",
"format": "uri"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/Package/CompletePackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CompletePackage extends Package implements CompletePackageInterface
protected $homepage = null;
/** @var array<string, string[]> Map of script name to array of handlers */
protected $scripts = [];
/** @var array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string} */
/** @var array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string, security?: string} */
protected $support = [];
/** @var array<array{url?: string, type?: string}> */
protected $funding = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Package/CompletePackageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public function setAuthors(array $authors): void;
/**
* Returns the support information
*
* @return array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string}
* @return array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string, security?: string}
*/
public function getSupport(): array;

/**
* Set the support information
*
* @param array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string} $support
* @param array{issues?: string, forum?: string, wiki?: string, source?: string, email?: string, irc?: string, docs?: string, rss?: string, chat?: string, security?: string} $support
*/
public function setSupport(array $support): void;

Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Package/Loader/ValidatingArrayLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function load(array $config, string $class = 'Composer\Package\CompletePa
}

if ($this->validateArray('support') && !empty($this->config['support'])) {
foreach (['issues', 'forum', 'wiki', 'source', 'email', 'irc', 'docs', 'rss', 'chat'] as $key) {
foreach (['issues', 'forum', 'wiki', 'source', 'email', 'irc', 'docs', 'rss', 'chat', 'security'] as $key) {
if (isset($this->config['support'][$key]) && !is_string($this->config['support'][$key])) {
$this->errors[] = 'support.'.$key.' : invalid value, must be a string';
unset($this->config['support'][$key]);
Expand All @@ -208,7 +208,7 @@ public function load(array $config, string $class = 'Composer\Package\CompletePa
unset($this->config['support']['irc']);
}

foreach (['issues', 'forum', 'wiki', 'source', 'docs', 'chat'] as $key) {
foreach (['issues', 'forum', 'wiki', 'source', 'docs', 'chat', 'security'] as $key) {
if (isset($this->config['support'][$key]) && !$this->filterUrl($this->config['support'][$key])) {
$this->warnings[] = 'support.'.$key.' : invalid value ('.$this->config['support'][$key].'), must be an http/https URL';
unset($this->config['support'][$key]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public static function successProvider(): array
'irc' => 'irc://example.org/example',
'rss' => 'http://example.org/rss',
'chat' => 'http://example.org/chat',
'security' => 'https://example.org/security',
],
'funding' => [
[
Expand Down Expand Up @@ -449,6 +450,7 @@ public static function warningProvider(): array
'issues' => 'foo:bar',
'wiki' => 'foo:bar',
'chat' => 'foo:bar',
'security' => 'foo:bar',
],
],
[
Expand All @@ -457,6 +459,7 @@ public static function warningProvider(): array
'support.issues : invalid value (foo:bar), must be an http/https URL',
'support.wiki : invalid value (foo:bar), must be an http/https URL',
'support.chat : invalid value (foo:bar), must be an http/https URL',
'support.security : invalid value (foo:bar), must be an http/https URL',
],
],
[
Expand Down

0 comments on commit cd137ee

Please sign in to comment.