Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scp/apikeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@
require('admin.inc.php');
include_once(INCLUDE_DIR.'class.api.php');

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
}

$api=null;
if($_REQUEST['id'] && !($api=API::lookup($_REQUEST['id'])))
$errors['err']=sprintf(__('%s: Unknown or invalid ID.'), __('API Key'));

if($_POST){
if (!isset($_POST['csrf_token'], $_SESSION['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
http_response_code(400);
exit('Invalid CSRF token');
}
switch(strtolower($_POST['do'])){
case 'update':
if(!$api){
Expand Down
14 changes: 14 additions & 0 deletions scp/canned.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
)),
));

// Generate CSRF token
if (!isset($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
// Add CSRF token to the form as a hidden field
$canned_form->addHiddenField('csrf_token', $_SESSION['csrf_token']);

// Set fields' attachments so exsting files stay put
if ($canned
&& $canned->attachments
Expand All @@ -53,6 +60,13 @@
}

if ($_POST) {
// CSRF validation
$csrf = $_POST['csrf_token'] ?? '';
if (!$csrf || !hash_equals($_SESSION['csrf_token'], $csrf)) {
header('HTTP/1.1 403 Forbidden');
exit('Invalid CSRF token');
}

switch(strtolower($_POST['do'])) {
case 'update':
if(!$canned) {
Expand Down
12 changes: 12 additions & 0 deletions scp/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@
**********************************************************************/
require('staff.inc.php');

// CSRF token generation
if (empty($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}

require_once INCLUDE_DIR . 'class.report.php';

if ($_POST['export']) {
// CSRF token validation
if (!isset($_POST['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
echo 'Invalid CSRF token';
exit;
}

$report = new OverviewReport($_POST['start'], $_POST['period']);
switch (true) {
case ($data = $report->getTabularData($_POST['export'])):
Expand Down
11 changes: 9 additions & 2 deletions scp/departments.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
$errors['err']=sprintf(__('%s: Unknown or invalid ID.'), __('department'));

if($_POST){
// CSRF token validation
if (!isset($_POST['csrf_token'], $_SESSION['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) {
header('HTTP/1.1 403 Forbidden');
echo 'Invalid CSRF token';
exit;
}

switch(strtolower($_POST['do'])){
case 'update':
if(!$dept){
Expand Down Expand Up @@ -63,7 +70,7 @@
$msg=sprintf(__('Successfully made %s PUBLIC'),
_N('selected department', 'selected departments', $count));
else
$warn=sprintf(__(
$warn=sprintf__(
/* Phrase will read:
<a> of <b> <selected objects> made PUBLIC */
'%1$d of %2$d %3$s made PUBLIC'), $num, $count,
Expand All @@ -82,7 +89,7 @@
$msg = sprintf(__('Successfully made %s PRIVATE'),
_N('selected department', 'selected epartments', $count));
else
$warn = sprintf(__(
$warn = sprintf__(
/* Phrase will read:
<a> of <b> <selected objects> made PRIVATE */
'%1$d of %2$d %3$s made PRIVATE'), $num, $count,
Expand Down