Skip to content

Commit 19731aa

Browse files
committed
chore: safe shell_exec
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent fcca74f commit 19731aa

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

src/Sign/JSignService.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,7 @@ private function pkcs12Read(JSignParam $params): array
187187
}
188188
file_put_contents($tempPassword, $password);
189189
file_put_contents($tempEncriptedOriginal, $certificate);
190-
shell_exec(<<<REPACK_COMMAND
191-
cat $tempPassword | openssl pkcs12 -legacy -in $tempEncriptedOriginal -nodes -out $tempDecrypted -passin stdin &&
192-
cat $tempPassword | openssl pkcs12 -in $tempDecrypted -export -out $tempEncriptedRepacked -passout stdin
193-
REPACK_COMMAND
194-
);
190+
$this->safeShellExec($tempPassword, $tempEncriptedOriginal, $tempDecrypted, $tempEncriptedRepacked);
195191
$certificateRepacked = file_get_contents($tempEncriptedRepacked);
196192
if ($certificateRepacked === false) {
197193
return [];
@@ -208,6 +204,25 @@ private function pkcs12Read(JSignParam $params): array
208204
return [];
209205
}
210206

207+
private function safeShellExec(
208+
string $tempPassword,
209+
string $tempEncriptedOriginal,
210+
string $tempDecrypted,
211+
string $tempEncriptedRepacked,
212+
): void
213+
{
214+
$tempPassword = escapeshellarg($tempPassword);
215+
$tempEncriptedOriginal = escapeshellarg($tempEncriptedOriginal);
216+
$tempDecrypted = escapeshellarg($tempDecrypted);
217+
$tempEncriptedRepacked = escapeshellarg($tempEncriptedRepacked);
218+
219+
shell_exec(<<<REPACK_COMMAND
220+
cat $tempPassword | openssl pkcs12 -legacy -in $tempEncriptedOriginal -nodes -out $tempDecrypted -passin stdin &&
221+
cat $tempPassword | openssl pkcs12 -in $tempDecrypted -export -out $tempEncriptedRepacked -passout stdin
222+
REPACK_COMMAND
223+
);
224+
}
225+
211226
private function exportToPkcs12(\OpenSSLCertificate|string $certificate, \OpenSSLAsymmetricKey|\OpenSSLCertificate|string $privateKey, string $password): string
212227
{
213228
$certContent = null;

0 commit comments

Comments
 (0)