Skip to content

Commit 85c9c2d

Browse files
authored
Merge pull request #174 from iMattPro/updates
Fix guards and bugs
2 parents 0716638 + 63cf132 commit 85c9c2d

7 files changed

Lines changed: 97 additions & 7 deletions

File tree

‎controller/main.php‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,10 @@ public function handle()
104104
$this->packager->create_extension($this->data);
105105
$filename = $this->packager->create_zip($this->data);
106106

107-
$response = new Response($filename);
107+
$response = new Response(file_get_contents($filename));
108108
$response->headers->set('Content-type', 'application/octet-stream');
109109
$response->headers->set('Content-Disposition', 'attachment; filename="' . basename($filename) . '";');
110110
$response->headers->set('Content-length', filesize($filename));
111-
$response->sendHeaders();
112-
$response->setContent(readfile($filename));
113111

114112
return $response;
115113
}

‎helper/validator.php‎

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,26 @@ public function validate_extension_name($value)
7575
*/
7676
public function validate_extension_display_name($value)
7777
{
78-
if ((string) $value !== '' && strpos($value, '"') === false)
78+
if ((string) $value !== '')
7979
{
80-
return htmlspecialchars_decode($value, ENT_NOQUOTES);
80+
return $this->validate_generated_string($value, 'SKELETON_INVALID_DISPLAY_NAME');
8181
}
8282

8383
throw new runtime_exception($this->language->lang('SKELETON_INVALID_DISPLAY_NAME'));
8484
}
8585

86+
/**
87+
* Validate the extension description for insertion into composer.json
88+
*
89+
* @param string $value The value to validate
90+
* @return string The valid value
91+
* @throws runtime_exception
92+
*/
93+
public function validate_extension_description($value)
94+
{
95+
return $this->validate_generated_string($value, 'SKELETON_INVALID_EXTENSION_DESCRIPTION');
96+
}
97+
8698
/**
8799
* Validate and require the extension date/time
88100
*
@@ -143,6 +155,8 @@ public function validate_vendor_name($value)
143155
*/
144156
public function validate_extension_homepage($value)
145157
{
158+
$value = $this->validate_generated_string($value, 'SKELETON_INVALID_EXTENSION_URL');
159+
146160
if ((string) $value !== '' && filter_var($value, FILTER_VALIDATE_URL) === false)
147161
{
148162
throw new runtime_exception($this->language->lang('SKELETON_INVALID_EXTENSION_URL'));
@@ -151,6 +165,18 @@ public function validate_extension_homepage($value)
151165
return $value;
152166
}
153167

168+
/**
169+
* Validate the author name
170+
*
171+
* @param string $value The value to validate
172+
* @return string The valid value
173+
* @throws runtime_exception
174+
*/
175+
public function validate_author_name($value)
176+
{
177+
return $this->validate_generated_string($value, 'SKELETON_INVALID_AUTHOR_NAME');
178+
}
179+
154180
/**
155181
* Validate the author homepage URL
156182
*
@@ -160,6 +186,8 @@ public function validate_extension_homepage($value)
160186
*/
161187
public function validate_author_homepage($value)
162188
{
189+
$value = $this->validate_generated_string($value, 'SKELETON_INVALID_AUTHOR_URL');
190+
163191
if ((string) $value !== '' && filter_var($value, FILTER_VALIDATE_URL) === false)
164192
{
165193
throw new runtime_exception($this->language->lang('SKELETON_INVALID_AUTHOR_URL'));
@@ -177,6 +205,8 @@ public function validate_author_homepage($value)
177205
*/
178206
public function validate_author_email($value)
179207
{
208+
$value = $this->validate_generated_string($value, 'SKELETON_INVALID_AUTHOR_EMAIL');
209+
180210
if ((string) $value !== '' && filter_var($value, FILTER_VALIDATE_EMAIL) === false)
181211
{
182212
throw new runtime_exception($this->language->lang('SKELETON_INVALID_AUTHOR_EMAIL'));
@@ -185,6 +215,18 @@ public function validate_author_email($value)
185215
return $value;
186216
}
187217

218+
/**
219+
* Validate the author role
220+
*
221+
* @param string $value The value to validate
222+
* @return string The valid value
223+
* @throws runtime_exception
224+
*/
225+
public function validate_author_role($value)
226+
{
227+
return $this->validate_generated_string($value, 'SKELETON_INVALID_AUTHOR_ROLE');
228+
}
229+
188230
/**
189231
* Validate and require the phpBB minimum version
190232
*
@@ -239,6 +281,29 @@ public function validate_php_version($value)
239281

240282
}
241283

284+
/**
285+
* Validate a string inserted without escaping into generated files.
286+
* Values must be safe inside a JSON string and must not contain a PHP comment
287+
* terminator. Request values are HTML escaped, so inspect their decoded form
288+
* and return safe characters without HTML entities.
289+
*
290+
* @param string $value The value to validate
291+
* @param string $error Language key used for invalid input
292+
* @return string The valid value
293+
* @throws runtime_exception
294+
*/
295+
protected function validate_generated_string($value, $error)
296+
{
297+
$decoded_value = htmlspecialchars_decode((string) $value, ENT_QUOTES);
298+
299+
if (preg_match('/["\\\\\x00-\x1F]/', $decoded_value) || strpos($decoded_value, '*/') !== false)
300+
{
301+
throw new runtime_exception($this->language->lang($error));
302+
}
303+
304+
return htmlspecialchars_decode((string) $value, ENT_NOQUOTES);
305+
}
306+
242307
/**
243308
* Version value check. Checks for values like:
244309
* 1.0.0-RC1

‎language/en/common.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
'SKELETON_QUESTION_EXTENSION_TIME_EXPLAIN' => 'YYYY-MM-DD, default: today',
5959

6060
'SKELETON_QUESTION_NUM_AUTHORS' => 'How many authors does the extension have',
61-
'SKELETON_QUESTION_NUM_AUTHORS_EXPLAIN' => 'default: 1',
6261

6362
'SKELETON_QUESTION_AUTHOR_NAME' => 'Please enter the author name',
6463
'SKELETON_QUESTION_AUTHOR_NAME_UI' => 'Author name',
@@ -148,8 +147,11 @@
148147
'SKELETON_TITLE_COMPONENT_INFO' => 'Components',
149148

150149
'SKELETON_INVALID_AUTHOR_EMAIL' => 'An author email is invalid',
150+
'SKELETON_INVALID_AUTHOR_NAME' => 'An author name is invalid',
151+
'SKELETON_INVALID_AUTHOR_ROLE' => 'An author role is invalid',
151152
'SKELETON_INVALID_AUTHOR_URL' => 'An author homepage URL is invalid',
152153
'SKELETON_INVALID_DISPLAY_NAME' => 'The display name you provided is invalid',
154+
'SKELETON_INVALID_EXTENSION_DESCRIPTION'=> 'The extension description you provided is invalid',
153155
'SKELETON_INVALID_EXTENSION_TIME' => 'The extension date you provided is invalid',
154156
'SKELETON_INVALID_EXTENSION_URL' => 'The extension homepage URL is invalid',
155157
'SKELETON_INVALID_EXTENSION_VERSION'=> 'The extension version you provided is invalid',

‎skeleton/console/command/sample.php.twig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ class sample extends \phpbb\console\command\command
5050
*
5151
* @param InputInterface $input An InputInterface instance
5252
* @param OutputInterface $output An OutputInterface instance
53+
*
54+
* @return int 0 if everything went fine, or an exit code
5355
*/
5456
protected function execute(InputInterface $input, OutputInterface $output): int
5557
{
5658
$output->writeln($this->user->lang('CLI_{{ EXTENSION.extension_name|upper }}_HELLO'));
59+
60+
return 0;
5761
}
5862
}

‎skeleton/notification/type/sample.php.twig‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ class sample extends \phpbb\notification\type\base
129129
*/
130130
public function get_url()
131131
{
132-
return $this->helper->route('{{ EXTENSION.vendor_name }}_{{ EXTENSION.extension_name }}_controller', $this->get_data('{{ EXTENSION.extension_name|lower }}_sample_name'));
132+
return $this->helper->route('{{ EXTENSION.vendor_name }}_{{ EXTENSION.extension_name }}_controller', [
133+
'name' => $this->get_data('{{ EXTENSION.extension_name|lower }}_sample_name'),
134+
]);
133135
}
134136
135137
/**

‎tests/controller/main_test.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ public function test_submit_success()
324324
$response = $this->get_controller($this->packager_mock)->handle();
325325

326326
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
327+
$this->assertSame('', $response->getContent());
328+
$this->assertSame('0', $response->headers->get('Content-length'));
327329
}
328330

329331
public function test_submit_exception()

‎tests/helper/validator_test.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public function valid_data(): array
4242

4343
['extension_display_name', 'Foo bar'],
4444
['extension_display_name', 'Foo >bar\'s< & world'],
45+
['extension_description', 'Foo >bar\'s< & world'],
46+
['author_name', 'Foo Bar'],
47+
['author_role', 'Developer'],
4548

4649
['extension_time', '0000-00-00'],
4750

@@ -145,6 +148,13 @@ public function invalid_data(): array
145148
['extension_display_name', '', 'SKELETON_INVALID_DISPLAY_NAME'],
146149
['extension_display_name', null, 'SKELETON_INVALID_DISPLAY_NAME'],
147150
['extension_display_name', 'Foo bar&quot;s world', 'SKELETON_INVALID_DISPLAY_NAME'],
151+
['extension_display_name', 'Foo */ bar', 'SKELETON_INVALID_DISPLAY_NAME'],
152+
['extension_display_name', 'Foo \\ bar', 'SKELETON_INVALID_DISPLAY_NAME'],
153+
154+
['extension_description', 'Foo &quot;bar&quot;', 'SKELETON_INVALID_EXTENSION_DESCRIPTION'],
155+
['extension_description', 'Foo \\ bar', 'SKELETON_INVALID_EXTENSION_DESCRIPTION'],
156+
['extension_description', "Foo\nbar", 'SKELETON_INVALID_EXTENSION_DESCRIPTION'],
157+
['extension_description', 'Foo */ bar', 'SKELETON_INVALID_EXTENSION_DESCRIPTION'],
148158

149159
['extension_time', '00-00-0000', 'SKELETON_INVALID_EXTENSION_TIME'],
150160
['extension_time', 'FOO', 'SKELETON_INVALID_EXTENSION_TIME'],
@@ -175,13 +185,20 @@ public function invalid_data(): array
175185

176186
['extension_homepage', 'www.web.com', 'SKELETON_INVALID_EXTENSION_URL'],
177187
['extension_homepage', 'foo', 'SKELETON_INVALID_EXTENSION_URL'],
188+
['extension_homepage', 'https://example.com/\\bad', 'SKELETON_INVALID_EXTENSION_URL'],
189+
190+
['author_name', 'Foo */ Bar', 'SKELETON_INVALID_AUTHOR_NAME'],
191+
['author_name', 'Foo &quot;Bar&quot;', 'SKELETON_INVALID_AUTHOR_NAME'],
192+
['author_role', 'Developer \\ Maintainer', 'SKELETON_INVALID_AUTHOR_ROLE'],
178193

179194
['author_homepage', 'www.web.com', 'SKELETON_INVALID_AUTHOR_URL'],
180195
['author_homepage', 'foo', 'SKELETON_INVALID_AUTHOR_URL'],
196+
['author_homepage', 'https://example.com/*/', 'SKELETON_INVALID_AUTHOR_URL'],
181197

182198
['author_email', 'mail.com', 'SKELETON_INVALID_AUTHOR_EMAIL'],
183199
['author_email', 'user@mail', 'SKELETON_INVALID_AUTHOR_EMAIL'],
184200
['author_email', 'foo', 'SKELETON_INVALID_AUTHOR_EMAIL'],
201+
['author_email', 'foo&quot;@example.com', 'SKELETON_INVALID_AUTHOR_EMAIL'],
185202

186203
['phpbb_version_min', '', 'SKELETON_INVALID_PHPBB_MIN_VERSION'],
187204
['phpbb_version_min', null, 'SKELETON_INVALID_PHPBB_MIN_VERSION'],

0 commit comments

Comments
 (0)