public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Stefan Schantl <stefan.schantl@ipfire.org>
To: development@lists.ipfire.org
Cc: Stefan Schantl <stefan.schantl@ipfire.org>
Subject: [PATCH 1/3] lldp.cgi: Add mission validation for description field
Date: Sat, 15 Nov 2025 11:07:56 +0100	[thread overview]
Message-ID: <20251115100758.7039-1-stefan.schantl@ipfire.org> (raw)

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 html/cgi-bin/lldp.cgi | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/html/cgi-bin/lldp.cgi b/html/cgi-bin/lldp.cgi
index 755d3dc46..9e30faa92 100644
--- a/html/cgi-bin/lldp.cgi
+++ b/html/cgi-bin/lldp.cgi
@@ -46,8 +46,13 @@ if ($cgiparams{"ACTION"} eq $Lang::tr{'save'}) {
 		$settings{'ENABLED'} = $cgiparams{'ENABLED'};
 	}
 
-	# XXX Validate the description
-	$settings{"DESCRIPTION"} = $cgiparams{"DESCRIPTION"};
+	# Validate the description
+	if (($cgiparams{"DESCRIPTION"} eq "") || ($cgiparams{"DESCRIPTION"} =~ /^[A-Za-z0-9_\-]+$/)) {
+		$settings{"DESCRIPTION"} = $cgiparams{"DESCRIPTION"};
+	} else {
+		# Add error message about invalid characters in description.
+		push(@errormessages, "$Lang::tr{'lldp invalid description'}");
+	}
 
 	# Don't continue on error
 	goto MAIN if (scalar @errormessages);
@@ -81,6 +86,9 @@ MAIN:
 		"ENABLED" => ($settings{"ENABLED"} eq "on") ? "checked" : "",
 	);
 
+	# Description field, defaults to CGI input otherwise use configured description.
+	my $description = $cgiparams{'DESCRIPTION'} // $settings{'DESCRIPTION'};
+
 	print <<END;
 		<form method="POST" action="">
 			<table class="form">
@@ -94,7 +102,7 @@ MAIN:
 				<tr>
 					<td>$Lang::tr{'description'}</td>
 					<td>
-						<input type="text" name="DESCRIPTION" value="$settings{'DESCRIPTION'}" />
+						<input type="text" name="DESCRIPTION" value="$description" />
 					</td>
 				</tr>
 
-- 
2.47.3



             reply	other threads:[~2025-11-15 10:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-15 10:07 Stefan Schantl [this message]
2025-11-15 10:07 ` [PATCH 2/3] lldp.cgi: Call binary for peers and do json stuff only if the service is enabled Stefan Schantl
2025-11-15 10:07 ` [PATCH 3/3] lldp.cgi: Show discovered peers in alphabetical order Stefan Schantl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251115100758.7039-1-stefan.schantl@ipfire.org \
    --to=stefan.schantl@ipfire.org \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox