Skip to content

Commit 283560d

Browse files
committed
Initial import
0 parents  commit 283560d

23 files changed

+4026
-0
lines changed

build.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- You may freely edit this file. See commented blocks below for -->
3+
<!-- some examples of how to customize the build. -->
4+
<!-- (If you delete it and reopen the project it will be recreated.) -->
5+
<!-- By default, only the Clean and Build commands use this build script. -->
6+
<!-- Commands such as Run, Debug, and Test only use this build script if -->
7+
<!-- the Compile on Save feature is turned off for the project. -->
8+
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
9+
<!-- in the project's Project Properties dialog box.-->
10+
<project name="OWASP_File_IO_Security" default="default" basedir=".">
11+
<description>Builds, tests, and runs the project OWASP File IO Security.</description>
12+
<import file="nbproject/build-impl.xml"/>
13+
<!--
14+
15+
There exist several targets which are by default empty and which can be
16+
used for execution of your tasks. These targets are usually executed
17+
before and after some main targets. They are:
18+
19+
-pre-init: called before initialization of project properties
20+
-post-init: called after initialization of project properties
21+
-pre-compile: called before javac compilation
22+
-post-compile: called after javac compilation
23+
-pre-compile-single: called before javac compilation of single file
24+
-post-compile-single: called after javac compilation of single file
25+
-pre-compile-test: called before javac compilation of JUnit tests
26+
-post-compile-test: called after javac compilation of JUnit tests
27+
-pre-compile-test-single: called before javac compilation of single JUnit test
28+
-post-compile-test-single: called after javac compilation of single JUunit test
29+
-pre-jar: called before JAR building
30+
-post-jar: called after JAR building
31+
-post-clean: called after cleaning build products
32+
33+
(Targets beginning with '-' are not intended to be called on their own.)
34+
35+
Example of inserting an obfuscator after compilation could look like this:
36+
37+
<target name="-post-compile">
38+
<obfuscate>
39+
<fileset dir="${build.classes.dir}"/>
40+
</obfuscate>
41+
</target>
42+
43+
For list of available properties check the imported
44+
nbproject/build-impl.xml file.
45+
46+
47+
Another way to customize the build is by overriding existing main targets.
48+
The targets of interest are:
49+
50+
-init-macrodef-javac: defines macro for javac compilation
51+
-init-macrodef-junit: defines macro for junit execution
52+
-init-macrodef-debug: defines macro for class debugging
53+
-init-macrodef-java: defines macro for class execution
54+
-do-jar-with-manifest: JAR building (if you are using a manifest)
55+
-do-jar-without-manifest: JAR building (if you are not using a manifest)
56+
run: execution of project
57+
-javadoc-build: Javadoc generation
58+
test-report: JUnit report generation
59+
60+
An example of overriding the target for project execution could look like this:
61+
62+
<target name="run" depends="OWASP_File_IO_Security-impl.jar">
63+
<exec dir="bin" executable="launcher.exe">
64+
<arg file="${dist.jar}"/>
65+
</exec>
66+
</target>
67+
68+
Notice that the overridden target depends on the jar target and not only on
69+
the compile target as the regular run target does. Again, for a list of available
70+
properties which you can use, check the target you are overriding in the
71+
nbproject/build-impl.xml file.
72+
73+
-->
74+
</project>

lib/junit/junit-3.8.2-api.zip

71.8 KB
Binary file not shown.

lib/junit/junit-3.8.2.jar

118 KB
Binary file not shown.

lib/junit_4/junit-4.10-javadoc.jar

415 KB
Binary file not shown.

lib/junit_4/junit-4.10-sources.jar

138 KB
Binary file not shown.

lib/junit_4/junit-4.10.jar

247 KB
Binary file not shown.

src/org/owasp/fileio/Encoder.java

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/**
2+
* This file is part of the Open Web Application Security Project (OWASP) Java File IO Security project. For details, please see
3+
* <a href="https://www.owasp.org/index.php/OWASP_Java_File_I_O_Security_Project">https://www.owasp.org/index.php/OWASP_Java_File_I_O_Security_Project</a>.
4+
*
5+
* Copyright (c) 2014 - The OWASP Foundation
6+
*
7+
* This API is published by OWASP under the Apache 2.0 license. You should read and accept the LICENSE before you use, modify, and/or redistribute this software.
8+
*
9+
* @author Jeff Williams <a href="http://www.aspectsecurity.com">Aspect Security</a> - Original ESAPI author
10+
* @author August Detlefsen <a href="http://www.codemagi.com">CodeMagi</a> - Java File IO Security Project lead
11+
* @created 2014
12+
*/
13+
package org.owasp.fileio;
14+
15+
import org.owasp.fileio.util.Utils;
16+
import java.util.ArrayList;
17+
import java.util.Iterator;
18+
import java.util.List;
19+
import java.util.Set;
20+
import org.owasp.fileio.codecs.Codec;
21+
import org.owasp.fileio.codecs.HTMLEntityCodec;
22+
import org.owasp.fileio.codecs.PercentCodec;
23+
24+
/**
25+
* Reference implementation of the Encoder interface. This implementation takes a whitelist approach to encoding, meaning that everything not specifically identified in a list of "immune" characters
26+
* is encoded.
27+
*/
28+
public class Encoder {
29+
30+
private static volatile Encoder singletonInstance;
31+
public final static char[] CHAR_ALPHANUMERICS = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
32+
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
33+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
34+
public static final Set<Character> ALPHANUMERICS;
35+
36+
static {
37+
ALPHANUMERICS = Utils.arrayToSet(Encoder.CHAR_ALPHANUMERICS);
38+
}
39+
private boolean restrictMultiple = true;
40+
private boolean restrictMixed = true;
41+
42+
public boolean isRestrictMultiple() {
43+
return restrictMultiple;
44+
}
45+
46+
public void setRestrictMultiple(boolean restrictMultiple) {
47+
this.restrictMultiple = restrictMultiple;
48+
}
49+
50+
public boolean isRestrictMixed() {
51+
return restrictMixed;
52+
}
53+
54+
public void setRestrictMixed(boolean restrictMixed) {
55+
this.restrictMixed = restrictMixed;
56+
}
57+
58+
public static Encoder getInstance() {
59+
if (singletonInstance == null) {
60+
synchronized (Encoder.class) {
61+
if (singletonInstance
62+
== null) {
63+
singletonInstance = new Encoder();
64+
}
65+
}
66+
}
67+
return singletonInstance;
68+
}
69+
// Codecs
70+
private List codecs = new ArrayList();
71+
private HTMLEntityCodec htmlCodec = new HTMLEntityCodec();
72+
private PercentCodec percentCodec = new PercentCodec();
73+
74+
/**
75+
* Instantiates a new DefaultEncoder with the default codecs
76+
*/
77+
public Encoder() {
78+
codecs.add(htmlCodec);
79+
codecs.add(percentCodec);
80+
}
81+
82+
/**
83+
* Instantiates a new DefaultEncoder with the default codecs
84+
*/
85+
public Encoder(List<Codec> codecs) {
86+
this.codecs = codecs;
87+
}
88+
89+
/**
90+
* {@inheritDoc}
91+
*/
92+
public String canonicalize(String input) {
93+
if (input == null) {
94+
return null;
95+
}
96+
97+
// Issue 231 - These are reverse boolean logic in the Encoder interface, so we need to invert these values - CS
98+
return canonicalize(input, restrictMultiple, restrictMixed);
99+
}
100+
101+
/**
102+
* {@inheritDoc}
103+
*/
104+
public String canonicalize(String input, boolean strict) {
105+
return canonicalize(input, strict, strict);
106+
}
107+
108+
/**
109+
* {@inheritDoc}
110+
*/
111+
public String canonicalize(String input, boolean restrictMultiple, boolean restrictMixed) {
112+
if (input == null) {
113+
return null;
114+
}
115+
116+
String working = input;
117+
Codec codecFound = null;
118+
int mixedCount = 1;
119+
int foundCount = 0;
120+
boolean clean = false;
121+
while (!clean) {
122+
clean = true;
123+
124+
// try each codec and keep track of which ones work
125+
Iterator i = codecs.iterator();
126+
while (i.hasNext()) {
127+
Codec codec = (Codec) i.next();
128+
String old = working;
129+
working = codec.decode(working);
130+
if (!old.equals(working)) {
131+
if (codecFound != null && codecFound != codec) {
132+
mixedCount++;
133+
}
134+
codecFound = codec;
135+
if (clean) {
136+
foundCount++;
137+
}
138+
clean = false;
139+
}
140+
}
141+
}
142+
143+
// do strict tests and handle if any mixed, multiple, nested encoding were found
144+
if (foundCount >= 2 && mixedCount > 1) {
145+
if (restrictMultiple || restrictMixed) {
146+
//TODO: throw new ValidationException("Input validation failure", "Multiple (" + foundCount + "x) and mixed encoding (" + mixedCount + "x) detected in " + input);
147+
} else {
148+
//TODO: logger.warning(Logger.SECURITY_FAILURE, "Multiple (" + foundCount + "x) and mixed encoding (" + mixedCount + "x) detected in " + input);
149+
}
150+
} else if (foundCount >= 2) {
151+
if (restrictMultiple) {
152+
//TODO: throw new ValidationException("Input validation failure", "Multiple (" + foundCount + "x) encoding detected in " + input);
153+
} else {
154+
//TODO: logger.warning(Logger.SECURITY_FAILURE, "Multiple (" + foundCount + "x) encoding detected in " + input);
155+
}
156+
} else if (mixedCount > 1) {
157+
if (restrictMixed) {
158+
//TODO: throw new ValidationException("Input validation failure", "Mixed encoding (" + mixedCount + "x) detected in " + input);
159+
} else {
160+
//TODO: logger.warning(Logger.SECURITY_FAILURE, "Mixed encoding (" + mixedCount + "x) detected in " + input);
161+
}
162+
}
163+
return working;
164+
}
165+
}

0 commit comments

Comments
 (0)