diff --git a/include/api.tickets.php b/include/api.tickets.php index 60907d56e9edc3bd1694ca633094c4fadc34f40f..1c5eaf052fbb80209d4a4a75e04647a1912e9fbf 100644 --- a/include/api.tickets.php +++ b/include/api.tickets.php @@ -12,7 +12,7 @@ class TicketApiController extends ApiController { $supported = array( "alert", "autorespond", "source", "topicId", "attachments" => array("*" => - array("name", "type", "data", "encoding") + array("name", "type", "data", "encoding", "size") ), "message", "ip", "priorityId" ); @@ -53,11 +53,11 @@ class TicketApiController extends ApiController { /* Validate data - overwrites parent's validator for additional validations. */ - function validate(&$data, $format) { + function validate(&$data, $format, $strict=true) { global $ost; //Call parent to Validate the structure - if(!parent::validate($data, $format)) + if(!parent::validate($data, $format, $strict) && $strict) $this->exerr(400, 'Unexpected or invalid data received'); //Nuke attachments IF API files are not allowed. diff --git a/include/class.api.php b/include/class.api.php index 65f0a90e89abaf42ecd5fa980d0b09299b738f3a..68e20c777a8701712299ff8cf5aab482afb24fd3 100644 --- a/include/class.api.php +++ b/include/class.api.php @@ -221,7 +221,7 @@ class ApiController { $this->exerr(400, $parser->lastError()); //Validate structure of the request. - $this->validate($data, $format); + $this->validate($data, $format, false); return $data; } @@ -241,19 +241,25 @@ class ApiController { * expected. It is assumed that the functions actually implementing the * API will further validate the contents of the request */ - function validateRequestStructure($data, $structure, $prefix="") { + function validateRequestStructure($data, $structure, $prefix="", $strict=true) { + global $ost; foreach ($data as $key=>$info) { if (is_array($structure) and is_array($info)) { $search = (isset($structure[$key]) && !is_numeric($key)) ? $key : "*"; if (isset($structure[$search])) { - $this->validateRequestStructure($info, $structure[$search], "$prefix$key/"); + $this->validateRequestStructure($info, $structure[$search], "$prefix$key/", $strict); continue; } } elseif (in_array($key, $structure)) { continue; } - return $this->exerr(400, "$prefix$key: Unexpected data received"); + if ($strict) + return $this->exerr(400, "$prefix$key: Unexpected data received"); + else + $ost->logWarning('API Unexpected Data', + "$prefix$key: Unexpected data received in API request", + false); } return true; @@ -263,11 +269,12 @@ class ApiController { * Validate request. * */ - function validate(&$data, $format) { + function validate(&$data, $format, $strict=true) { return $this->validateRequestStructure( $data, - $this->getRequestStructure($format, $data) - ); + $this->getRequestStructure($format, $data), + "", + $strict); } /** diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php index 237d1d9f78b79621edb6a46134c765a20e9b28ca..4e83c6f4843b78a29bf992a0190e515b1e82e8ff 100644 --- a/include/class.mailfetch.php +++ b/include/class.mailfetch.php @@ -663,6 +663,7 @@ class MailFetcher { $attachments[] = array( 'cid' => @$at->AttachContentId ?: false, 'data' => $at, + 'size' => @$at->DataSize ?: null, 'type' => @$at->AttachMimeTag ?: false, 'name' => $at->getName(), ); diff --git a/include/class.mailparse.php b/include/class.mailparse.php index dad841ffb1a5067c5e37ef4a42df5ff622ab0fc1..703258b5632f4e835d21c1a7368e70042c76987f 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -424,6 +424,7 @@ class Mail_Parse { $files[] = array( 'cid' => @$at->AttachContentId ?: false, 'data' => $at->getData(), + 'size' => @$at->DataSize ?: null, 'type' => @$at->AttachMimeTag ?: false, 'name' => $at->getName(), ); diff --git a/include/tnef_decoder.php b/include/tnef_decoder.php index 45ee5b5c074db014d98e69af2c2238697c550820..e0f7869ba82b4ce554ada486efbfb1ae9cc4bb67 100644 --- a/include/tnef_decoder.php +++ b/include/tnef_decoder.php @@ -491,6 +491,7 @@ class TnefStreamParser { break; case self::attAttachData: $attach->_setData($info['data']); + $attach->_setDataSize($info['length']); break; } } @@ -557,6 +558,10 @@ class TnefAttachment extends AbstractTnefObject { $this->Data = $data; } + function _setDataSize($size) { + $this->DataSize = $size; + } + function getData() { if (isset($this->Data)) return $this->Data;