diff options
Diffstat (limited to 'Master/Agile Software Development/TestApp/src/Parser/JavascriptParser.java')
| -rw-r--r-- | Master/Agile Software Development/TestApp/src/Parser/JavascriptParser.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Master/Agile Software Development/TestApp/src/Parser/JavascriptParser.java b/Master/Agile Software Development/TestApp/src/Parser/JavascriptParser.java new file mode 100644 index 0000000..4cfe0ec --- /dev/null +++ b/Master/Agile Software Development/TestApp/src/Parser/JavascriptParser.java @@ -0,0 +1,44 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package Parser; + +import testapp.data.ExternalJavascriptItem; +import testapp.data.Item; +import java.util.logging.*; + +public class JavascriptParser { + private Item rootNode; + + private static final Logger logger = Logger.getLogger(JavascriptParser.class.getName()); + + + public JavascriptParser(Item rootNode) { + this.rootNode=rootNode; + } + + public ExternalJavascriptItem parse(String url) { + // Todo: http client to recieve url and put contents into code + String code=new String(); + return parseCode(code, url); + } + + public ExternalJavascriptItem parseCode(String code, String url) { + // the only evil js code should be + //document.write('<script type="text/javascript" src="'+ jsFile + '"></scr' + 'ipt>'); + // => nearly impossible to parse, so we search only for "src" string + // if found, code is marked suspicious + // could be tricked by spliting the string! + // + + ExternalJavascriptItem externalJavascriptItem=new ExternalJavascriptItem(url,rootNode); + rootNode.add(externalJavascriptItem); + if(code.contains("src")) { + externalJavascriptItem.setSuspiciousCode(); + } + + return externalJavascriptItem; + } +} |
