Skip to content

Commit cfcc3dc

Browse files
author
arshan.dabirsiaghi@gmail.com
committed
- more changes
1 parent 4a836e1 commit cfcc3dc

3 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/main/java/org/owasp/esapi/filters/waf/AppGuardianConfiguration.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
public class AppGuardianConfiguration {
99

10-
1110
/*
1211
* Each stage has an associated set of rules.
1312
*/
@@ -17,18 +16,18 @@ public class AppGuardianConfiguration {
1716

1817
private int defaultFailAction = DONT_BLOCK;
1918

19+
public static int MAX_FILE_SIZE = Integer.MAX_VALUE;
20+
2021
private List<Rule> beforeBodyRules;
2122
private List<Rule> afterBodyRules;
2223
private List<Rule> beforeResponseRules;
2324

24-
List<String> allowedMethods;
25+
private List<String> allowedMethods;
2526

2627
public AppGuardianConfiguration() {
27-
2828
beforeBodyRules = new ArrayList<Rule>();
2929
afterBodyRules = new ArrayList<Rule>();
3030
beforeResponseRules = new ArrayList<Rule>();
31-
3231
}
3332

3433
public void setDefaultFailRule(int defaultFailAction) {

src/main/java/org/owasp/esapi/filters/waf/internal/InterceptingHTTPServletRequest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
import org.apache.commons.fileupload.FileUploadException;
1717
import org.apache.commons.fileupload.servlet.ServletFileUpload;
1818
import org.apache.commons.fileupload.util.Streams;
19+
import org.owasp.esapi.filters.waf.AppGuardianConfiguration;
1920
import org.owasp.esapi.filters.waf.UploadTooLargeException;
2021

2122
public class InterceptingHTTPServletRequest extends HttpServletRequestWrapper {
2223

2324
private Vector<Parameter> allParameters;
2425
private Vector<String> allParameterNames;
25-
private static int MAX_FILE_SIZE = Integer.MAX_VALUE;
2626
private static int CHUNKED_BUFFER_SIZE = 1024;
2727

2828
public InterceptingHTTPServletRequest(HttpServletRequest request) throws UploadTooLargeException, FileUploadException, IOException {
@@ -75,17 +75,20 @@ public InterceptingHTTPServletRequest(HttpServletRequest request) throws UploadT
7575
* regular form field. Our job is to stream it
7676
* to make sure it's not too big.
7777
*/
78+
7879
ByteArrayOutputStream baos = new ByteArrayOutputStream(request.getContentLength());
7980
byte buffer[] = new byte[CHUNKED_BUFFER_SIZE];
81+
8082
int size = 0;
83+
int len = 0;
8184

82-
while(size <= MAX_FILE_SIZE ) {
83-
int len = stream.read(buffer, 0, CHUNKED_BUFFER_SIZE);
85+
while ( len != -1 || size <= AppGuardianConfiguration.MAX_FILE_SIZE ) {
86+
len = stream.read(buffer, 0, CHUNKED_BUFFER_SIZE);
8487
size += len;
8588
baos.write(stream.read());
8689
}
8790

88-
if ( size > MAX_FILE_SIZE) {
91+
if ( size > AppGuardianConfiguration.MAX_FILE_SIZE) {
8992
throw new UploadTooLargeException("param: " + name);
9093
}
9194
}

src/main/java/org/owasp/esapi/filters/waf/rules/AuthenticatedRule.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,25 @@
22

33
import javax.servlet.http.HttpServletRequest;
44
import javax.servlet.http.HttpServletResponse;
5+
import javax.servlet.http.HttpSession;
56

67
public class AuthenticatedRule extends Rule {
78

8-
@Override
9+
private String sessionAttribute;
10+
11+
public AuthenticatedRule(String sessionAttribute) {
12+
this.sessionAttribute = sessionAttribute;
13+
}
14+
915
public boolean check(HttpServletRequest request,
1016
HttpServletResponse response) {
11-
// TODO Auto-generated method stub
17+
18+
HttpSession session = request.getSession();
19+
20+
if ( session != null && session.getAttribute(sessionAttribute) != null ) {
21+
return true;
22+
}
23+
1224
return false;
1325
}
1426

0 commit comments

Comments
 (0)