Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

files: Verify files attached to a FileUploadField #2618

Merged
merged 1 commit into from Oct 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion include/class.forms.php
Expand Up @@ -1517,6 +1517,9 @@ function ajaxUpload($bypass=false) {
if (!($id = AttachmentFile::upload($file)))
Http::response(500, 'Unable to store file: '. $file['error']);

// This file is allowed for attachment in this session
$_SESSION[':uploadedFiles'][$id] = 1;

return $id;
}

Expand Down Expand Up @@ -2206,7 +2209,27 @@ function getValue() {
elseif ($data && is_array($data) && !isset($data[$this->name]))
return array();

return parent::getValue();

// Files uploaded here MUST have been uploaded by this user and
// identified in the session
if ($files = parent::getValue()) {
$allowed = array();
// Files already attached to the field are allowed
foreach ($this->field->getFiles() as $F) {
// FIXME: This will need special porting in v1.10
$allowed[$F['id']] = 1;
}
// New files uploaded in this session are allowed
if (isset($_SESSION[':uploadedFiles'])) {
$allowed += $_SESSION[':uploadedFiles'];
}
foreach ($files as $i=>$F) {
if (!isset($allowed[$F])) {
unset($files[$i]);
}
}
}
return $files;
}
}

Expand Down