summaryrefslogtreecommitdiffstats
path: root/Master/Agile Software Development/TestApp/src/Parser/JavascriptParser.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Agile Software Development/TestApp/src/Parser/JavascriptParser.java
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Agile Software Development/TestApp/src/Parser/JavascriptParser.java')
-rw-r--r--Master/Agile Software Development/TestApp/src/Parser/JavascriptParser.java44
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;
+ }
+}