-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't allow Semicolon or CRLF injection
CSP-Builder is a developer tool. It is not meant to be used with user input. However, the ability to inject CSP directives or additional headers violates the principle of least astonishment. This was reported via user demonia on HackerOne.
- Loading branch information
1 parent
613c0d2
commit 1a1a85f
Showing
3 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ParagonIE\CSPBuilderTest; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use ParagonIE\CSPBuilder\CSPBuilder; | ||
|
||
class InvalidInputTest extends TestCase | ||
{ | ||
public function testRejectSemicolon() | ||
{ | ||
$csp = (new CSPBuilder([])) | ||
->setReportUri('https://example.com/csp_report.php; hello world') | ||
->compile(); | ||
|
||
$this->assertStringNotContainsString( | ||
$csp, | ||
'report-uri https://example.com/csp_report.php; hello world', | ||
'Semicolon injection is possible' | ||
); | ||
} | ||
|
||
public function testRejectCrLf() | ||
{ | ||
$csp = (new CSPBuilder([])) | ||
->setReportUri("https://example.com/csp_report.php;\r\nContent-Type:text/plain") | ||
->compile(); | ||
|
||
$this->assertStringNotContainsString( | ||
$csp, | ||
"\r\nContent-Type:", | ||
"CRLF Injection is possible" | ||
); | ||
} | ||
} |