-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from iftechfoundation/csp
Adopt a Content Security Policy
- Loading branch information
Showing
40 changed files
with
848 additions
and
547 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
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,32 @@ | ||
<?php | ||
// https://stackoverflow.com/a/34149536/54829 | ||
/** | ||
* Generate a random string, using a cryptographically secure | ||
* pseudorandom number generator (random_int) | ||
* | ||
* For PHP 7, random_int is a PHP core function | ||
* For PHP 5.x, depends on https://github.com/paragonie/random_compat | ||
* | ||
* @param int $length How many characters do we want? | ||
* @param string $keyspace A string of all possible characters | ||
* to select from | ||
* @return string | ||
*/ | ||
function random_str( | ||
$length, | ||
$keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | ||
) { | ||
$str = ''; | ||
$max = 61; // mb_strlen($keyspace, '8bit') - 1; | ||
if ($max < 1) { | ||
throw new Exception('$keyspace must be at least two characters long'); | ||
} | ||
for ($i = 0; $i < $length; ++$i) { | ||
$str .= $keyspace[random_int(0, $max)]; | ||
} | ||
return $str; | ||
} | ||
global $nonce; | ||
$nonce = random_str(8); | ||
|
||
header("Content-Security-Policy: default-src 'self' ifdb.org www.google.com 'nonce-$nonce'; style-src 'self' 'unsafe-inline';"); |
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
Oops, something went wrong.