PicUploader icon indicating copy to clipboard operation
PicUploader copied to clipboard

XX vulnerability in index.php

Open enferas opened this issue 2 years ago • 3 comments

Hello,

I would like to report for possible XSS vulnerability.

In file https://github.com/xiebruce/PicUploader/blob/master/index.php

$data = [
	'code' => 'success',
	'data' => [
		'filename' => $_FILES['file']['name'],
		'url' => $isWeb ? $link['formatLink'] : $link,
              //专用于web上传,其它客户端上传该参数无用
              'notFormatUrl' => $isWeb ? $link['notFormatLink'] : '',
	],
];

header('Content-Type: application/json; charset=UTF-8');
$json = json_encode($data, JSON_UNESCAPED_UNICODE);
echo $json;

It is possible to do the injection with the name of the file through $_FILES['file']['name'].

enferas avatar Jul 22 '22 20:07 enferas

Thank you for reporting, I add a htmlspecialchars() to convert something like <script>alert('sdfds')</script> to html entities.

htmlspecialchars($_FILES['file']['name'])

Don't know if this can solve the issue?

xiebruce avatar Jul 23 '22 08:07 xiebruce

Thank you for your response.

Yes exactly that solve the issue.

I would like also to mention to security issue in https://github.com/xiebruce/PicUploader/blob/master/settings/SettingController.php

public function getStorageParams($params){
		$key = $params['key'];
		$jsonFile = $this->storagesDir.'/storage-'.$key.'.json';
		if(is_file($jsonFile)){
			$columns = json_decode(file_get_contents($jsonFile), true);
			$code = 0;
		}else{
			//....
		}
		unset($columns['name']);
		
		$returnArr = [
			'code' => $code,
			'data' => $columns,
		];
		//....
		return json_encode($returnArr);
	}
	
	public function setStorageParams($params){
		//...
               $config = json_encode($_POST, JSON_UNESCAPED_SLASHES);
                //...
                $config = str_replace('\u202a', '', $config);
		file_put_contents($jsonFile, $config);
		//....
	}

You are saving the $_POST in a file through the function getStorageParams without sanitization. Then you use the function getStorageParams to retrieve the information. Are you using this file in your project ? if yes, we need to sanitize the input.

enferas avatar Jul 23 '22 20:07 enferas

Thank you so much, now I update the code as below

$post = [];
foreach($_POST as $key=>$val){
	$post[$key] = htmlspecialchars($val);
}
$config = json_encode($post, JSON_UNESCAPED_SLASHES);

xiebruce avatar Jul 24 '22 06:07 xiebruce

CVE-2022-36748 is assigned to the first report in /master/index.php

enferas avatar Sep 21 '22 18:09 enferas

CVE-2022-36748 is assigned to the first report in /master/index.php

I've delete that tag v2.6.3

xiebruce avatar Sep 22 '22 06:09 xiebruce

CVE-2022-41442 is assigned to the second report.

enferas avatar Oct 03 '22 15:10 enferas

Thank you for your response.

Yes exactly that solve the issue.

I would like also to mention to security issue in https://github.com/xiebruce/PicUploader/blob/master/settings/SettingController.php

public function getStorageParams($params){
		$key = $params['key'];
		$jsonFile = $this->storagesDir.'/storage-'.$key.'.json';
		if(is_file($jsonFile)){
			$columns = json_decode(file_get_contents($jsonFile), true);
			$code = 0;
		}else{
			//....
		}
		unset($columns['name']);
		
		$returnArr = [
			'code' => $code,
			'data' => $columns,
		];
		//....
		return json_encode($returnArr);
	}
	
	public function setStorageParams($params){
		//...
               $config = json_encode($_POST, JSON_UNESCAPED_SLASHES);
                //...
                $config = str_replace('\u202a', '', $config);
		file_put_contents($jsonFile, $config);
		//....
	}

You are saving the $_POST in a file through the function getStorageParams without sanitization. Then you use the function getStorageParams to retrieve the information. Are you using this file in your project ? if yes, we need to sanitize the input.

Second report? did you mean this? but I've already fix it. If I didn't, please point it out(coz I can't understand you clearly.)

xiebruce avatar Oct 03 '22 16:10 xiebruce

Yes, the vulnerability already fixed. thanks for your confirmation. It is just some process for gaining a CVE which will help me in my research. When the person find a security issues he can ask for CVE, then it is assigned to the discovery https://www.cve.org/

enferas avatar Oct 04 '22 17:10 enferas

OK, got it.

xiebruce avatar Oct 05 '22 08:10 xiebruce