Skip to content

Commit

Permalink
MDL-14591 - better security when reawakening an interupted export
Browse files Browse the repository at this point in the history
  • Loading branch information
mjollnir_ committed Aug 20, 2008
1 parent 349242a commit beb4ac1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions lang/en_utf8/portfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
$string['nonprimative'] = 'A non primative value was passed as a callback argument to portfolio_add_button. Refusing to continue. The key was $a->key and the value was $a->value';
$string['notexportable'] = 'Sorry, but the type of content you are trying to export is not exportable';
$string['notimplemented'] = 'Sorry, but you are trying to export content in some format that is not yet implemented ($a)';
$string['notyours'] = 'You are trying to resume a portfolio export that doesn\'t belong to you!';
$string['nouploaddirectory'] = 'Could not create a temporary directory to package your data into';
$string['portfolio'] = 'Portfolio';
$string['portfolios'] = 'Portfolios';
Expand Down
13 changes: 12 additions & 1 deletion lib/portfoliolib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,8 @@ final class portfolio_exporter {
*/
private $id;

private $sesskey;

/**
* construct a new exporter for use
*
Expand Down Expand Up @@ -1826,7 +1828,7 @@ public function get($field) {
return $this->{$field};
}
$a = (object)array('property' => $field, 'class' => get_class($this));
throw new portfolio_export_exception($this, 'invalidproperty', 'portfolio', $a);
throw new portfolio_export_exception($this, 'invalidproperty', 'portfolio', '', $a);
}

/**
Expand Down Expand Up @@ -2306,6 +2308,15 @@ private function new_file_record_base($name) {
);
}

public function verify_rewaken() {
global $USER;
if ($this->get('user')->id != $USER->id) {
throw new portfolio_exception('notyours', 'portfolio');
}
if (!confirm_sesskey($this->get('sesskey'))) {
throw new portfolio_exception('confirmsesskeybad');
}
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion portfolio/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
$exporter = null;
$dataid = 0;

if (!$dataid = optional_param('id') ) {
if (!$dataid = optional_param('id', '', PARAM_INT) ) {
if (isset($SESSION->portfolioexport)) {
$dataid = $SESSION->portfolioexport;
}
}
if ($dataid) {
$exporter = portfolio_exporter::rewaken_object($dataid);
$exporter->verify_rewaken();
if ($cancel = optional_param('cancel', 0, PARAM_RAW)) {
$exporter->cancel_request();
}
Expand All @@ -32,6 +33,7 @@
}
$instance->set('user', $USER);
$exporter->set('instance', $instance);
$exporter->set('sesskey', sesskey());
$exporter->save();
}
}
Expand Down

0 comments on commit beb4ac1

Please sign in to comment.