git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] gitweb: esc_html (short) error message in die_error

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 7, 2010, 20:51 UTC
Message-ID
<20100207204803.11146.57731.stgit@localhost.localdomain>
In-Reply-To
<20100207204539.11146.36972.stgit@localhost.localdomain>

The error message (second argument to die_error) is meant to be short, one-line text description of given error. A few callers call die_error with error message containing unescaped user supplied data ($hash, $file_name). Instead of forcing callers to escape data, simply call esc_html on the parameter.

Note that optional third parameter, which contains detailed error description, is meant to be HTML formatted, and therefore should be not escaped.

While at it update esc_html synopsis/usage, and bring default error description to read 'Internal Server Error' (titlecased).

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Alternate solution would be to do escaping in call sites for die_error.

But in error messages shown on 'die' via CGI::Carp qw(fatalsToBrowser) the error message is HTML escaped, so in fact we are following here this "calling convention".

Note that for any patch relied on 'Internal server error' as error message, it must be changed to not fail wrongly.

 gitweb/gitweb.perl |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index a5bc359..e393f65 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3374,7 +3374,7 @@ sub git_footer_html {
 	      "</html>";
 }
 
-# die_error(<http_status_code>, <error_message>)
+# die_error(<http_status_code>, <error_message>[, <detailed_html_description>])
 # Example: die_error(404, 'Hash not found')
 # By convention, use the following status codes (as defined in RFC 2616):
 # 400: Invalid or missing CGI parameters, or
@@ -3389,7 +3389,7 @@ sub git_footer_html {
 #      or down for maintenance).  Generally, this is a temporary state.
 sub die_error {
 	my $status = shift || 500;
-	my $error = shift || "Internal server error";
+	my $error = esc_html(shift || "Internal Server Error");
 	my $extra = shift;
 
 	my %http_responses = (
Previous: Jakub NarebskiNext: Jakub Narebski
Message 2 of 5 in “gitweb: Improve escaping”
  1. 0/2 gitweb: Improve escapingJakub Narebski, Feb 7, 2010
  2. 1/2 gitweb: esc_html (short) error message in die_errorJakub Narebski, Feb 7, 2010
  3. Jakub NarebskiFeb 17, 2010
  4. 2/2 gitweb: Protect escaping functions against calling on undefJakub Narebski, Feb 7, 2010
  5. Jakub NarebskiFeb 17, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.