@@ -169,7 +169,7 @@ - (void)setText:(NSString*)text
169169 } else {
170170
171171 if (text) {
172- text = [self addSlashes : text];
172+ text = [self sanitizeHTML : text];
173173 } else {
174174 text = @" " ;
175175 }
@@ -187,7 +187,7 @@ - (void)setHtml:(NSString*)html
187187 } else {
188188
189189 if (html) {
190- html = [self addSlashes : html];
190+ html = [self sanitizeHTML : html];
191191 } else {
192192 html = @" " ;
193193 }
@@ -205,7 +205,7 @@ - (void)setPlaceholderText:(NSString*)placeholderText
205205 if (!self.domLoaded ) {
206206 self.preloadedPlaceholderText = placeholderText;
207207 } else {
208- placeholderText = [self addSlashes : placeholderText];
208+ placeholderText = [self sanitizeHTML : placeholderText];
209209 NSString * javascript = [NSString stringWithFormat: @" %@ .setPlaceholderText(\" %@ \" );" , [self wrappedNodeJavascriptAccessor ], placeholderText];
210210
211211 [self .webView stringByEvaluatingJavaScriptFromString: javascript];
@@ -232,14 +232,14 @@ - (void)setPlaceholderColor:(UIColor *)placeholderColor
232232#pragma mark - URL & HTML utilities
233233
234234/* *
235- * @brief Adds slashes to the specified HTML string, to prevent injections when calling JS
235+ * @brief Adds slashes and removes script tags from the specified HTML string, to prevent injections when calling JS
236236 * code.
237237 *
238- * @param html The HTML string to add slashes to . Cannot be nil.
238+ * @param html The HTML string to sanitize . Cannot be nil.
239239 *
240- * @returns The HTML string with the added slashes .
240+ * @returns The sanitized HTML string.
241241 */
242- - (NSString *)addSlashes : (NSString *)html
242+ - (NSString *)sanitizeHTML : (NSString *)html
243243{
244244 html = [html stringByReplacingOccurrencesOfString: @" \\ " withString: @" \\\\ " ];
245245 html = [html stringByReplacingOccurrencesOfString: @" \" " withString: @" \\\" " ];
@@ -252,6 +252,9 @@ - (NSString *)addSlashes:(NSString *)html
252252 html = [html stringByReplacingOccurrencesOfString: @" \u2028 " withString: @" \\ u2028" ];
253253 html = [html stringByReplacingOccurrencesOfString: @" \u2029 " withString: @" \\ u2029" ];
254254
255+ html = [html stringByReplacingOccurrencesOfString: @" <script>" withString: @" <script>" options: NSCaseInsensitiveSearch range: NSMakeRange (0 , [html length ])];
256+ html = [html stringByReplacingOccurrencesOfString: @" </script>" withString: @" </script>" options: NSCaseInsensitiveSearch range: NSMakeRange (0 , [html length ])];
257+
255258 return html;
256259}
257260
0 commit comments