--- a/usr/local/www/interfaces_qinq_edit.php
+++ b/usr/local/www/interfaces_qinq_edit.php
@@ -114,6 +114,10 @@
 	$qinqentry['if'] = $_POST['if'];
 	$qinqentry['tag'] = $_POST['tag'];
 
+	if (empty($_POST['if']) || !does_interface_exist($_POST['if'])) {
+		$input_errors[] = gettext("A valid parent interface must be specified.");
+	}
+
 	if ($_POST['autogroup'] == "yes") {
 		$qinqentry['autogroup'] = true;
 	}
@@ -186,7 +190,7 @@
 			if ((count($delmembers) > 0) || (count($addmembers) > 0)) {
 				$parent = $qinqentry['vlanif'];
 				foreach ($delmembers as $tag) {
-					exec("/sbin/ifconfig {$parent}.{$tag} destroy");
+					exec("/sbin/ifconfig " . escapeshellarg("{$parent}.{$tag}") . " destroy");
 				}
 
 				foreach ($addmembers as $member) {
--- a/etc/inc/interfaces.inc
+++ b/etc/inc/interfaces.inc
@@ -492,7 +492,7 @@
 		return;
 	}
 
-	exec("/sbin/ifconfig {$vlanif} vlanproto 802.1ad > /dev/null 2>&1");
+	exec("/sbin/ifconfig " . escapeshellarg($vlanif) . " vlanproto 802.1ad > /dev/null 2>&1");
 
 	/* make sure the parent is up */
 	interfaces_bring_up($qinqif);
@@ -503,7 +503,7 @@
 	}
 
 	if (interface_is_vlan($qinqif) == NULL) {
-		mwexec("/sbin/ifconfig {$qinqif} promisc\n");
+		mwexec("/sbin/ifconfig " . escapeshellarg($qinqif) . " promisc\n");
 	}
 
 	$macaddr = get_interface_mac($qinqif);
@@ -571,7 +571,11 @@
 		return;
 	}
 
-	exec("/sbin/ifconfig vlan create vlandev {$if} vlan {$tag} name {$vlanif}");
+	if (!does_interface_exist($if) || !is_numericint($tag)) {
+		log_error(sprintf(gettext("interface_qinq2_configure called with invalid if or tag.%s"), "\n"));
+		return;
+	}
+	exec("/sbin/ifconfig vlan create vlandev " . escapeshellarg($if) . " vlan " . escapeshellarg($tag) . " name " . escapeshellarg($vlanif));
 
 	return $vlanif;
 }
@@ -3025,7 +3029,7 @@
 	if (substr($vip['interface'], 0, 4) == "_vip") {
 		$carpvip = get_configured_vip($vip['interface']);
 		$iface = $carpvip['interface'];
-		$vhid = "vhid {$carpvip['vhid']}";
+		$vhid = "vhid " . escapeshellarg((int)$carpvip['vhid']);
 	}
 	mwexec("/sbin/ifconfig " . escapeshellarg($realif) ." {$af} ". escapeshellarg($vip['subnet']) ."/" . escapeshellarg($vip['subnet_bits']) . " alias {$gateway} {$vhid}");
 	unset($iface, $af, $realif, $carpvip, $vhid, $gateway);
--- a/usr/local/www/wizards/openvpn_wizard.inc
+++ b/usr/local/www/wizards/openvpn_wizard.inc
@@ -431,6 +431,11 @@
 	if ($portused != 0)
 		$input_errors[] = "The specified 'Local port' is in use. Please enter a port not already in use.";
 
+	if (!empty($_POST['defaultdomain']) && !is_domain($_POST['defaultdomain']))
+		$input_errors[] = "The field 'Default Domain' must contain a valid domain name.";
+	if (!empty($_POST['nbtscope']) && preg_match('/[\r\n"\\\\]/', $_POST['nbtscope']))
+		$input_errors[] = "The field 'NetBIOS Scope' contains invalid characters.";
+
 	if (!isset($_POST['generatetlskey']) && isset($_POST['tlsauthentication']))
 		if (!strstr($_POST['tlssharedkey'], "-----BEGIN OpenVPN Static key V1-----") ||
 			!strstr($_POST['tlssharedkey'], "-----END OpenVPN Static key V1-----"))
@@ -683,7 +688,7 @@
 	if (isset($pconfig['step10']['dynip']) && ($pconfig['step10']['dynip'] == "on"))
 		$server['dynamic_ip'] = "yes";
 	$server['topology'] = $pconfig['step10']['topology'];
-	if (isset($pconfig['step10']['defaultdomain']))
+	if (isset($pconfig['step10']['defaultdomain']) && is_domain($pconfig['step10']['defaultdomain']))
 		$server['dns_domain'] = $pconfig['step10']['defaultdomain'];
 	if (isset($pconfig['step10']['dns1']))
 		$server['dns_server1'] = $pconfig['step10']['dns1'];
@@ -704,7 +709,7 @@
 	if (isset($pconfig['step10']['nbtenable'])) {
 		$server['netbios_ntype'] = $pconfig['step10']['nbttype'];
 		if (isset($pconfig['step10']['nbtscope'])) {
-			$server['netbios_scope'] = $pconfig['step10']['nbtscope'];
+			$server['netbios_scope'] = preg_replace('/[\r\n"\\\\]/', '', $pconfig['step10']['nbtscope']);
 		}
 
 		$server['netbios_enable'] = $pconfig['step10']['nbtenable'];
--- a/usr/local/www/vpn_openvpn_server.php
+++ b/usr/local/www/vpn_openvpn_server.php
@@ -514,6 +514,12 @@
 		}
 	}
 
+	if ($pconfig['dns_domain_enable']) {
+		if (!empty($pconfig['dns_domain']) && !is_domain(trim($pconfig['dns_domain']))) {
+			$input_errors[] = gettext("The field 'DNS Default Domain' must contain a valid domain name");
+		}
+	}
+
 	if ($pconfig['dns_server_enable']) {
 		if (!empty($pconfig['dns_server1']) && !is_ipaddr(trim($pconfig['dns_server1']))) {
 			$input_errors[] = gettext("The field 'DNS Server #1' must contain a valid IPv4 or IPv6 address");
@@ -562,6 +568,9 @@
 		if (!empty($pconfig['netbios_ntype']) &&
 		    !array_key_exists($pconfig['netbios_ntype'], $netbios_nodetypes)) {
 			$input_errors[] = gettext("The selected NetBIOS Node Type is not valid.");
+		}
+		if (!empty($pconfig['netbios_scope']) && preg_match('/[\r\n"\\\\]/', $pconfig['netbios_scope'])) {
+			$input_errors[] = gettext("The field 'NetBIOS Scope ID' contains invalid characters.");
 		}
 	}
 
--- a/etc/inc/openvpn.inc
+++ b/etc/inc/openvpn.inc
@@ -720,8 +720,9 @@
 
 function openvpn_add_dhcpopts(& $settings, & $conf) {
 
-	if (!empty($settings['dns_domain'])) {
-		$conf .= "push \"dhcp-option DOMAIN {$settings['dns_domain']}\"\n";
+	if (!empty($settings['dns_domain']) && is_domain($settings['dns_domain'])) {
+		$clean_dns_domain = preg_replace('/[\r\n"\\\\]/', '', $settings['dns_domain']);
+		$conf .= "push \"dhcp-option DOMAIN {$clean_dns_domain}\"\n";
 	}
 
 	if (!empty($settings['dns_server1'])) {
@@ -761,7 +762,8 @@
 			$conf .= "push \"dhcp-option NBT {$settings['dhcp_nbttype']}\"\n";
 		}
 		if (!empty($settings['dhcp_nbtscope'])) {
-			$conf .= "push \"dhcp-option NBS {$settings['dhcp_nbtscope']}\"\n";
+			$clean_nbtscope = preg_replace('/[\r\n"\\\\]/', '', $settings['dhcp_nbtscope']);
+			$conf .= "push \"dhcp-option NBS {$clean_nbtscope}\"\n";
 		}
 
 		if (!empty($settings['wins_server1'])) {
--- a/usr/local/pfSense/include/www/firewall_virtual_ip.inc
+++ b/usr/local/pfSense/include/www/firewall_virtual_ip.inc
@@ -140,6 +140,9 @@
 	 */
 	switch ($post['mode']) {
 		case 'carp':
+			if (!is_numericint($post['vhid']) || ((int)$post['vhid'] < 1) || ((int)$post['vhid'] > 255)) {
+				$input_errors[] = gettext("A valid VHID must be specified (integer between 1 and 255).");
+			}
 			/* verify against reusage of vhids */
 			$idtracker = 0;
 			foreach (config_get_path('virtualip/vip', []) as $vip) {
@@ -199,7 +202,7 @@
 
 		/* CARP specific fields */
 		if ($post['mode'] === "carp") {
-			$vipent['vhid'] = $post['vhid'];
+			$vipent['vhid'] = (int)$post['vhid'];
 			$vipent['advskew'] = $post['advskew'];
 			$vipent['advbase'] = $post['advbase'];
 
--- a/etc/inc/pfsense-utils.inc
+++ b/etc/inc/pfsense-utils.inc
@@ -786,9 +786,9 @@
 	if ($vip == NULL || !isset($vip['vhid']))
 		return "";
 
-	$vhid = $vip['vhid'];
+	$vhid = (int)$vip['vhid'];
 	$carp_query = [];
-	exec("/sbin/ifconfig {$interface} | /usr/bin/grep \"carp:.* vhid {$vhid} \"", $carp_query);
+	exec("/sbin/ifconfig " . escapeshellarg($interface) . " | /usr/bin/grep " . escapeshellarg("carp:.* vhid {$vhid} "), $carp_query);
 	foreach ($carp_query as $int) {
 		if (stripos($int, "MASTER"))
 			return "MASTER";
--- a/etc/inc/shaper.inc
+++ b/etc/inc/shaper.inc
@@ -3658,10 +3658,10 @@
 		$this->buckets = $buckets;
 	}
 	function SetNumber($number) {
-		$this->qnumber = $number;
+		$this->qnumber = (int)$number;
 	}
 	function GetNumber() {
-		return $this->qnumber;
+		return (int)$this->qnumber;
 	}
 	function GetPlr() {
 		return $this->plr;
@@ -3870,8 +3870,8 @@
 			$q->delete_queue();
 		}
 		unset_dn_object_by_reference($this->GetLink());
-		mwexec("/sbin/dnctl pipe delete " . $this->GetNumber());
-		mwexec("/sbin/dnctl sched delete " . $this->GetNumber());
+		mwexec("/sbin/dnctl pipe delete " . escapeshellarg((int)$this->GetNumber()));
+		mwexec("/sbin/dnctl sched delete " . escapeshellarg((int)$this->GetNumber()));
 	}
 	function GetBandwidth() {
 		return $this->qbandwidth;
@@ -4793,7 +4793,7 @@
 	function delete_queue() {
 		cleanup_dnqueue_from_rules($this->GetQname());
 		unset_dn_object_by_reference($this->GetLink());
-		mwexec("/sbin/dnctl queue delete " . $this->GetNumber());
+		mwexec("/sbin/dnctl queue delete " . escapeshellarg((int)$this->GetNumber()));
 	}
 
 	function validate_input($data, &$input_errors) {
--- a/usr/local/www/vpn_ipsec_mobile.php
+++ b/usr/local/www/vpn_ipsec_mobile.php
@@ -273,6 +273,8 @@
 	if ($pconfig['login_banner_enable']) {
 		if (!strlen($pconfig['login_banner'])) {
 			$input_errors[] = gettext("A valid value for 'Login Banner' must be specified.");
+		} elseif (preg_match('/[\r\n\{\}#"]/', $pconfig['login_banner'])) {
+			$input_errors[] = gettext("The 'Login Banner' cannot contain newlines, quotes, '#', '{', or '}'.");
 		}
 	}
 
--- a/etc/inc/ipsec.inc
+++ b/etc/inc/ipsec.inc
@@ -1868,7 +1868,7 @@
 
 		if (!empty(config_get_path('ipsec/client/login_banner'))) {
 			$ssconf['charon']['plugins']['attr'][] = "# Login Banner";
-			$ssconf['charon']['plugins']['attr']['28672'] = config_get_path('ipsec/client/login_banner');
+			$ssconf['charon']['plugins']['attr']['28672'] = preg_replace('/[\r\n\{\}#"]/', '', config_get_path('ipsec/client/login_banner'));
 		}
 
 		if (config_path_enabled('ipsec/client', 'save_passwd')) {
