1 | <?php |
||
17 | class DeployController extends Controller |
||
18 | { |
||
19 | /** |
||
20 | * The origin of the webhook request. |
||
21 | * |
||
22 | * @var Morphatic\AutoDeploy\Origins\OriginInterface |
||
23 | */ |
||
24 | private $origin; |
||
25 | |||
26 | /** |
||
27 | * The URL of the repo to be cloned. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $repoUrl; |
||
32 | |||
33 | /** |
||
34 | * The absolute path of the directory on the server that contains the project. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $webroot; |
||
39 | |||
40 | /** |
||
41 | * The absolute path of the directory where the new deployment will be set up. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $installDir; |
||
46 | |||
47 | /** |
||
48 | * A log of the results of the entire deploy process. |
||
49 | * |
||
50 | * @var Monolog\Logger |
||
51 | */ |
||
52 | private $log; |
||
53 | |||
54 | /** |
||
55 | * The commit ID for this commit. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | private $commitId; |
||
60 | |||
61 | /** |
||
62 | * The commit ID for this commit. |
||
63 | * |
||
64 | * @var AdamBrett\ShellWrapper\Runners\Exec |
||
65 | */ |
||
66 | private $shell; |
||
67 | |||
68 | /** |
||
69 | * The result of this commit. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | private $result; |
||
74 | |||
75 | /** |
||
76 | * Create a new DeployController instance. |
||
77 | * |
||
78 | * @param Morphatic\AutoDeploy\Origins\OriginInterface $origin The origin of the webhook |
||
79 | * @param AdamBrett\ShellWrapper\Runners\Exec $exec The shell command execution class |
||
80 | */ |
||
81 | 36 | public function __construct(OriginInterface $origin, Exec $exec) |
|
91 | |||
92 | /** |
||
93 | * Handles incoming webhook requests. |
||
94 | */ |
||
95 | 12 | public function index() |
|
137 | |||
138 | /** |
||
139 | * Runs a shell command, logs, and handles the result. |
||
140 | * |
||
141 | * @param AdamBrett\ShellWrapper\CommandInterface $cmd The text of the command to be run |
||
142 | * |
||
143 | * @return bool True if the command was successful, false on error |
||
144 | */ |
||
145 | 12 | private function ex(CommandInterface $cmd) |
|
159 | |||
160 | /** |
||
161 | * Backup the database. |
||
162 | * |
||
163 | * @return bool True if the database was successfully backed up. False on error. |
||
164 | */ |
||
165 | 12 | private function backupDatabase() |
|
208 | |||
209 | /** |
||
210 | * Create a new directory parallel to the webroot and clone the project into that directory. |
||
211 | * |
||
212 | * @return bool True if the clone is successful. False otherwise. |
||
213 | */ |
||
214 | 10 | private function pull() |
|
235 | |||
236 | /** |
||
237 | * Copy the .env file from the new deploy directory. |
||
238 | * |
||
239 | * @return bool True if the update is successful. False otherwise. |
||
240 | */ |
||
241 | 2 | private function copyEnv() |
|
249 | |||
250 | /** |
||
251 | * Update composer and run composer update. |
||
252 | * |
||
253 | * @return bool True if the update is successful. False otherwise. |
||
254 | */ |
||
255 | 8 | private function composer() |
|
269 | |||
270 | /** |
||
271 | * Run npm update. |
||
272 | * |
||
273 | * @return bool True if npm is successful. False otherwise. |
||
274 | */ |
||
275 | 8 | private function npm() |
|
285 | |||
286 | /** |
||
287 | * Run any necessary database migrations. |
||
288 | * |
||
289 | * @return bool True if the migration is successful. False otherwise. |
||
290 | */ |
||
291 | 8 | private function migrate() |
|
304 | |||
305 | /** |
||
306 | * Run any necessary database migrations. |
||
307 | * |
||
308 | * @return bool True if the migration is successful. False otherwise. |
||
309 | */ |
||
310 | 8 | private function seed() |
|
321 | |||
322 | /** |
||
323 | * Symlinks the new deploy directory to the webroot. |
||
324 | * |
||
325 | * @return bool True if the symlink is successful. False otherwise. |
||
326 | */ |
||
327 | 8 | private function deploy() |
|
339 | } |
||
340 |
$step
can contain request data and is used in code execution context(s) leading to a potential security vulnerability.General Strategies to prevent injection
In general, it is advisable to prevent any user-data to reach this point. This can be done by white-listing certain values:
For numeric data, we recommend to explicitly cast the data: