CVE-2014-125108 (published 2023-12-23T17:15Z)

A vulnerability was found in w3c online-spellchecker-py up to 20140130. It has been rated as problematic. This issue affects some unknown processing of the file spellchecker. The manipulation leads to cross site scripting. The attack may be initiated remotely. The complexity of an attack is rather high. The exploitation is known to be difficult. The identifier of the patch is d6c21fd8187c5db2a50425ff80694149e75d722e. It is recommended to apply a patch to fix this issue. The identifier VDB-248849 was assigned to this vulnerability.

CVSS v3 base score: 6.1, MEDIUM (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-79
cwe_name: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
description: The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
extended_description: 
            Cross-site scripting (XSS) vulnerabilities occur when:
            
               Untrusted data enters a web application, typically from a web request.
               The web application dynamically generates a web page that contains this untrusted data.
               During page generation, the application does not prevent the data from containing content that is executable by a web browser, such as JavaScript, HTML tags, HTML attributes, mouse events, Flash, ActiveX, etc.
               A victim visits the generated web page through a web browser, which contains malicious script that was injected using the untrusted data.
               Since the script comes from a web page that was sent by the web server, the victim's web browser executes the malicious script in the context of the web server's domain.
               This effectively violates the intention of the web browser's same-origin policy, which states that scripts in one domain should not be able to access resources or run code in a different domain.
            
            There are three main kinds of XSS:
            
               
                  Type 1: Reflected XSS (or Non-Persistent) - 
         			The server reads data directly from the HTTP request and reflects it back in the HTTP response. Reflected XSS exploits occur when an attacker causes a victim to supply dangerous content to a vulnerable web application, which is then reflected back to the victim and executed by the web browser. The most common mechanism for delivering malicious content is to include it as a parameter in a URL that is posted publicly or e-mailed directly to the victim. URLs constructed in this manner constitute the core of many phishing schemes, whereby an attacker convinces a victim to visit a URL that refers to a vulnerable site. After the site reflects the attacker's content back to the victim, the content is executed by the victim's browser.
               
                  Type 2: Stored XSS (or Persistent) - 
               The application stores dangerous data in a database, message forum, visitor log, or other trusted data store. At a later time, the dangerous data is subsequently read back into the application and included in dynamic content. From an attacker's perspective, the optimal place to inject malicious content is in an area that is displayed to either many users or particularly interesting users. Interesting users typically have elevated privileges in the application or interact with sensitive data that is valuable to the attacker. If one of these users executes malicious content, the attacker may be able to perform privileged operations on behalf of the user or gain access to sensitive data belonging to the user. For example, the attacker might inject XSS into a log message, which might not be handled properly when an administrator views the logs.
            
               
                  Type 0: DOM-Based XSS - 
               In DOM-based XSS, the client performs the injection of XSS into the page; in the other types, the server performs the injection. DOM-based XSS generally involves server-controlled, trusted script that is sent to the client, such as Javascript that performs sanity checks on a form before the user submits it. If the server-supplied script processes user-supplied data and then injects it back into the web page (such as with dynamic HTML), then DOM-based XSS is possible.
            
            
            Once the malicious script is injected, the attacker can perform a variety of malicious activities. The attacker could transfer private information, such as cookies that may include session information, from the victim's machine to the attacker. The attacker could send malicious requests to a web site on behalf of the victim, which could be especially dangerous to the site if the victim has administrator privileges to manage that site. Phishing attacks could be used to emulate trusted web sites and trick the victim into entering a password, allowing the attacker to compromise the victim's account on that web site. Finally, the script could exploit a vulnerability in the web browser itself possibly taking over the victim's machine, sometimes referred to as "drive-by hacking."
            In many cases, the attack can be launched without the victim even being aware of it. Even with careful users, attackers frequently use a variety of methods to encode the malicious portion of the attack, such as URL encoding or Unicode, so the request looks less suspicious.
         
         

Fix information:
repo_url: https://github.com/w3c/online-spellchecker-py
commit_details: repo_url: https://github.com/w3c/online-spellchecker-py
author: brett
author_date: 2014-01-31 14:25:58+00:00
msg: Defend against RCE and XSS; modernize.

RCE was theoretically possible depending on how strict
cgi.parse_header() reads Content-Type.  If it ever returned shell
metacharacters, those would be passed directly to the shell.

This patch switches the code from popen2 to subprocess, since the
latter is deprecated, and we get lots of warnings about that in our
Apache error logs.
repository: repo_url: https://github.com/w3c/online-spellchecker-py
repo_name: w3c/online-spellchecker-py
description: Online spellchecker
repo_language: Python
owner: w3c
file_changes: filename: spellchecker
change_type: ModificationType.MODIFY
diff: @@ -15,25 +15,24 @@ $Id$
  branched from v 1.46
 """
 
-import os
 import cgi
+import checkremote
+import http_auth
+import os
 import sys
-import string
 import urlparse
-import popen2
 
-customized_dico="/usr/local/share/aspell/w3c.dat"
+from cleanhtml import *
+from subprocess import Popen, PIPE
+
 languages = {"en_US":"English","fr":"French"}
 def format_option(a,b,c):
         if a:
                 selected=""
                 if a==c:
                         selected=" selected='selected'"
-                return "<option value='%s'%s>%s</option>" % (a,selected,b)
-
-def concat(a,b):
-        return a+b
-
+                return clean_format("<option value='%s'%s>%s</option>",
+                                    a, selected, b)
 
 Page1 ="""Content-Type:text/html; charset=utf-8
 
@@ -93,108 +92,93 @@ Last Modified: $Date$
 """
 
 def format(fp,suggest):
-	line = fp.readline()
 	words = {}
-	count = 0
-	while line!="":
-		if line!="\n" and line !="*\n" and line[0]!="@":
-			line = line[:-1]
-			parts = string.split(line,": ")
-			fields = string.split(parts[0]," ")
-			if fields[0]=="&":
-				values = string.split(parts[1],", ")
-				if (not words.has_key(fields[1])):
-					words[fields[1]]=values
+        for line in fp:
+                line = line.rstrip('\n')
+		if line and line != "*" and line[0] != "@":
+			parts = line.split(': ')
+			fields = parts[0].split()
+                        if fields[1] in words:
+                                continue
+			elif fields[0]=="&":
+                                words[fields[1]] = parts[1].split(", ")
 			elif fields[0]=="#":
-				if (not words.has_key(fields[1])):
-					words[fields[1]]=[]
-		elif line=="\n":
-			count = count + 1
-		line = fp.readline()
-	offsets = {}
-	count = 0
-	if len(words):
-                keys = words.keys()
-                keys.sort()
-		print "<form action=\"http://www.w3.org/Team/update_dictionary\" method=\"post\"><ol>"
-		for error in keys:
-			print "<li>\"<span class='no'>%s</span>\" (<input type=\"checkbox\" name=\"list[]\" value=\"%s\"/> add to the dictionary)" % (error,error)
-
-			if len(words[error]) and suggest:
-				print "; suggestions:<ul class='suggestions'>"
-				for option in words[error]:
-					print "<li>%s</li>" % option
-				print "</ul>"				
-			print "</li>"
-		print "</ol><p><label><input type=\"submit\" value=\"Update dictionary\"/> (W3C Comm Team only)</label></p></form>"
-	else:
+                                words[fields[1]] = []
+	if not words:
 		print "<p><span class='yes'>No errors</span> found.</p>"
+                return
+        for error in sorted(words):
+                clean_print("<li>\"<span class='no'>%s</span>\"", error)
+                if words[error] and suggest:
+                        print "; suggestions:<ul class='suggestions'>"
+                        for option in words[error]:
+                                clean_print("<li>%s</li>", option)
+                        print "</ul>"				
+                print "</li>"
+
+def getLangSetup(fields):
+        lang = fields.getfirst('lang')
+        if lang not in languages:
+                lang = 'en_US'
+        lang_opts = ''.join(format_option(code, languages[code], lang)
+                            for code in languages)
+        return lang, lang_opts
+
+def getSuggestSetup(fields):
+        if fields.getfirst('suggest') == 'on':
+                return True, " checked='checked'"
+        return False, ""
+
+def getURI(fields):
+        uri = fields.getfirst('uri')
+        if (not uri) and ('referrer' in fields):
+                uri = os.environ.get('HTTP_REFERER')
+        return uri
 
 if __name__ == '__main__':
-	if  os.environ.has_key('SCRIPT_NAME'):
-		fields = cgi.FieldStorage()
-		uri ="" 
-		uri_text =""
-		uri_text1=""
-		suggest=0
-		suggest_txt=''
-		if fields.has_key('uri'):
-			uri = fields['uri'].value
-                elif fields.has_key('referrer') and os.environ.has_key('HTTP_REFERER'):
-                        uri = os.environ['HTTP_REFERER']
-                if uri:
-			uri_text1="for %s" % (cgi.escape(uri))
-			uri_text=" for <a href=\"%s\">%s</a>" %(cgi.escape(uri),cgi.escape(uri))
-                lang = "en_US"
-                if fields.has_key('lang') and fields['lang'].value in languages.keys():
-                        lang=fields['lang'].value
-                languages_options = reduce(concat,map(format_option,languages.keys(),languages.values(),[lang for x in languages.keys()]))
-
-		if fields.has_key('suggest'):
-			if fields['suggest'].value=='on':
-				suggest=1
-				suggest_txt=" checked='checked'"
-		if uri:
-			import http_auth
-			url_opener = http_auth.ProxyAuthURLopener()
-			try:
-				fp = url_opener.open(uri)
-			except IOError as e:
-				url_opener.error = "I/O error: %s %s" % (e.errno,e.strerror)
-				fp = None
-			print Page1 % ('<meta name="ROBOTS" content="NOINDEX,NOFOLLOW"/>',uri_text1,uri_text,cgi.escape(uri),languages_options,suggest_txt)
-			if fp:
-                                personal = "--personal=%s" % customized_dico
-                                if lang!="en_US":
-                                        personal = ""
-                                headers = fp.info()
-                                charset_opt = ""
-                                if headers.has_key('Content-Type'):
-                                        contentType = cgi.parse_header(headers["Content-Type"])
-                                        if contentType[1].has_key('charset'):
-                                                charset_opt = "-assume_charset=%s" % contentType[1]['charset']
-	        		command = "/usr/bin/lynx  %s -cfg=/usr/local/lib/lynx.cfg -nolist -dump -stdin|/usr/bin/aspell --encoding=utf-8 --lang %s -a %s --sug-mode=fast" % (charset_opt,lang,personal)
-
-        	                (piperfd,pipewfd,pipeErr) = popen2.popen3(command)
-
-				pipewfd.write(fp.read())
-				fp.close()
-				pipewfd.close()
-				# Need to find a way to display any errors if relevant
-				processingErrors=""
-				if (processingErrors):
-					print "<p>The following error occurred when trying to process your request :</p><pre class='no'>"
-					print "</pre>"
-					pipeErr.close()
-				if (piperfd):
-					print "<h2>Errors found in the page</h2>"
-					format(piperfd,suggest)
-					piperfd.close()
-			else:
-				print "<p><span class='no'>Unable to read</span> <a href='%s'>%s</a> (%s). Sorry, check the URI.</p>" % (cgi.escape(uri),cgi.escape(uri), url_opener.error)
-		else:
-			print Page1 % ('',uri_text1,uri_text,cgi.escape(uri),languages_options,suggest_txt)
-		print Page2
-
-
-
+        fields = cgi.FieldStorage()
+        lang, languages_options = getLangSetup(fields)
+        suggest, suggest_txt = getSuggestSetup(fields)
+        uri = getURI(fields)
+        if not uri:
+                print Page1 % ('', '', '', clean_str(uri), languages_options,
+                               suggest_txt)
+                print Page2
+                sys.exit()
+
+        uri_text1 = clean_format("for %s", uri)
+        uri_text = clean_format(" for <a href=\"%s\">%s</a>", uri, uri)
+        print Page1 % ('<meta name="ROBOTS" content="NOINDEX,NOFOLLOW"/>',
+                       uri_text1, uri_text, clean_str(uri), languages_options,
+                       suggest_txt)
+
+        url_opener = http_auth.ProxyAuthURLopener()
+        try:
+                fp = url_opener.open(uri)
+        except IOError as e:
+                url_opener.error = "I/O error: %s %s" % (e.errno,e.strerror)
+                fp = None
+        if fp is None:
+                clean_print("<p><span class='no'>Unable to read</span> <a href='%s'>%s</a> (%s). Sorry, check the URI.</p>", uri, uri, url_opener.error)
+                print Page2
+                sys.exit()
+
+        headers = fp.info()
+        lynx_cmd = ['/usr/bin/lynx', '-cfg=/usr/local/lib/lynx.cfg', '-nolist',
+                    '-dump', '-stdin']
+        if headers.has_key('Content-Type'):
+                contentType = cgi.parse_header(headers['Content-Type'])
+                if contentType[1].has_key('charset'):
+                        lynx_cmd.append('-assume_charset=%s' %
+                                        contentType[1]['charset'])
+
+        lynx_proc = Popen(lynx_cmd, stdin=fp, stdout=PIPE)
+        aspell_proc = Popen(['/usr/bin/aspell', '-a', '--encoding=utf-8',
+                             '--sug-mode=fast', '--lang', lang],
+                            stdin=lynx_proc.stdout, stdout=PIPE)
+        lynx_proc.wait()
+        lynx_proc.stdout.close()
+        print "<h2>Errors found in the page</h2>"
+        format(aspell_proc.stdout, suggest)
+        aspell_proc.stdout.close()
+        print Page2

programming_language: Python