Skip to content

Commit

Permalink
prevent XSS via buttonText
Browse files Browse the repository at this point in the history
  • Loading branch information
Buck Golemon committed Dec 28, 2012
1 parent 17a52f4 commit f6e5097
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions core/Flash/SWFUpload.as
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ package {
import flash.text.TextFormat;
import flash.ui.Mouse;
import flash.utils.Timer;
import flash.xml.XMLNode;
import flash.xml.XMLNodeType;

import FileItem;
import ExternalCall;
Expand Down Expand Up @@ -231,7 +233,7 @@ package {
this.stage.addChild(this.buttonCursorSprite);

// Get the movie name
this.movieName = root.loaderInfo.parameters.movieName || '';
this.movieName = root.loaderInfo.parameters.movieName || '';
this.movieName = this.movieName.replace(/[^a-zA-Z0-9\_\.\-]/g, "");

// **Configure the callbacks**
Expand Down Expand Up @@ -348,7 +350,8 @@ package {
}

try {
this.SetButtonText(String(root.loaderInfo.parameters.buttonText));
// HTML-escape strings that come from the user, preventing XSS.
this.SetButtonText(htmlEscape(String(root.loaderInfo.parameters.buttonText)));
} catch (ex:Object) {
this.SetButtonText("");
}
Expand Down Expand Up @@ -1147,7 +1150,7 @@ package {
var style:StyleSheet = new StyleSheet();
style.parseCSS(this.buttonTextStyle);
this.buttonTextField.styleSheet = style;
this.buttonTextField.htmlText = this.buttonText;
this.buttonTextField.htmlText = '<span class="button-text">' + this.buttonText + '</span>';
}

private function SetButtonTextPadding(left:Number, top:Number):void {
Expand Down Expand Up @@ -1516,5 +1519,9 @@ package {
}
}

public function htmlEscape(str:String):String {
return XML( new XMLNode( XMLNodeType.TEXT_NODE, str ) ).toXMLString();
}

}
}

0 comments on commit f6e5097

Please sign in to comment.