52 $formFieldArray = array();
53 foreach ($formFieldNames as $formField) {
54 $formFieldParts = explode(
'[', $formField);
55 $currentPosition = &$formFieldArray;
56 for ($i = 0; $i < count($formFieldParts); $i++) {
57 $formFieldPart = $formFieldParts[$i];
58 if (substr($formFieldPart, -1) ==
']') {
59 $formFieldPart = substr($formFieldPart, 0, -1);
62 if (!is_array($currentPosition)) {
63 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForRequestHashGenerationException(
'The form field name "' . $formField .
'" collides with a previous form field name which declared the field as string. (String overridden by Array)', 1255072197);
65 if ($i == count($formFieldParts) - 1) {
66 if (isset($currentPosition[$formFieldPart]) && is_array($currentPosition[$formFieldPart])) {
67 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForRequestHashGenerationException(
'The form field name "' . $formField .
'" collides with a previous form field name which declared the field as array. (Array overridden by String)', 1255072588);
70 if ($formFieldPart ===
'') {
71 $currentPosition[] = 1;
73 $currentPosition[$formFieldPart] = 1;
76 if ($formFieldPart ===
'') {
77 throw new \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForRequestHashGenerationException(
'The form field name "' . $formField .
'" is invalid. Reason: "[]" used not as last argument.', 1255072833);
79 if (!isset($currentPosition[$formFieldPart])) {
80 $currentPosition[$formFieldPart] = array();
82 $currentPosition = &$currentPosition[$formFieldPart];
86 if ($fieldNamePrefix !==
'') {
87 $formFieldArray = isset($formFieldArray[$fieldNamePrefix]) ? $formFieldArray[$fieldNamePrefix] : array();
99 $serializedFormFieldArray = serialize($formFieldArray);
100 return $serializedFormFieldArray . $this->hashService->generateHmac($serializedFormFieldArray);
113 if (!$request->getInternalArgument(
'__hmac')) {
114 $request->setHmacVerified(FALSE);
117 $hmac = $request->getInternalArgument(
'__hmac');
118 if (strlen($hmac) < 40) {
119 throw new \TYPO3\CMS\Extbase\Security\Exception\SyntacticallyWrongRequestHashException(
'Request hash too short. This is a probably manipulation attempt!', 1255089361);
121 $serializedFieldNames = substr($hmac, 0, -40);
123 $hash = substr($hmac, -40);
124 if ($this->hashService->validateHmac($serializedFieldNames, $hash)) {
125 $requestArguments = $request->getArguments();
127 unset($requestArguments[
'__referrer']);
128 unset($requestArguments[
'__hmac']);
130 $request->setHmacVerified(TRUE);
132 $request->setHmacVerified(FALSE);
135 $request->setHmacVerified(FALSE);
147 foreach ($requestArguments as $argumentName => $argumentValue) {
148 if (!isset($allowedFields[$argumentName])) {
151 if (is_array($requestArguments[$argumentName]) && is_array($allowedFields[$argumentName])) {
155 } elseif (!is_array($requestArguments[$argumentName]) && !is_array($allowedFields[$argumentName])) {
156 } elseif (!is_array($requestArguments[$argumentName]) && $requestArguments[$argumentName] ===
'' && is_array($allowedFields[$argumentName])) {
verifyRequest(\TYPO3\CMS\Extbase\Mvc\Web\Request $request)
serializeAndHashFormFieldArray($formFieldArray)
generateRequestHash($formFieldNames, $fieldNamePrefix='')
checkFieldNameInclusion(array $requestArguments, array $allowedFields)