Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaars committed Sep 20, 2019
1 parent f29b923 commit c8ef848
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public Assignment(String name) {
}

public Assignment(String name, String path, List<String> hints) {
if (path.equals("")) {
System.out.println(name);
}
this.name = name;
this.path = path;
this.hints = hints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,32 @@
import org.owasp.webgoat.assignments.AssignmentEndpoint;
import org.owasp.webgoat.assignments.AssignmentPath;
import org.owasp.webgoat.assignments.AttackResult;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class HttpBasicsInterceptRequest extends AssignmentEndpoint {

// @ExceptionHandler(MissingServletRequestParameterException.class)
// public AttackResult handleMissingParams() {
// return trackProgress(failed().feedback("http-proxies.intercept.failure").build());
// }

@GetMapping("/HttpProxies/intercept-request")
@RequestMapping(path = "/HttpProxies/intercept-request", method = {RequestMethod.POST, RequestMethod.GET})
@ResponseBody
public AttackResult completed(@RequestHeader(value = "x-request-intercepted", required = false) Boolean headerValue,
@RequestParam(value = "changeMe", required = false) String paramValue) {
@RequestParam(value = "changeMe", required = false) String paramValue, HttpServletRequest request) {
if (HttpMethod.POST.matches(request.getMethod())) {
return trackProgress(failed().feedback("http-proxies.intercept.failure").build());
}
if (headerValue != null && paramValue != null && headerValue && "Requests are tampered easily".equalsIgnoreCase(paramValue)) {
return trackProgress(success().feedback("http-proxies.intercept.success").build());
} else {
return trackProgress(failed().feedback("http-proxies.intercept.failure").build());
}
}

// @PostMapping("/HttpProxies/intercept-request")
// @ResponseBody
// public AttackResult post() {
// return trackProgress(failed().feedback("http-proxies.intercept.failure").build());
// }
@ExceptionHandler(MissingServletRequestParameterException.class)
public AttackResult handleMissingParams() {
return trackProgress(failed().feedback("http-proxies.intercept.failure").build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public void missingHeader() throws Exception {
.andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(false)));
}

// @Test
// public void whenPostAssignmentShouldNotPass() throws Exception {
// mockMvc.perform(MockMvcRequestBuilders.post("/HttpProxies/intercept-request")
// .header("x-request-intercepted", "true")
// .param("changeMe", "Requests are tampered easily"))
// .andExpect(status().isOk())
// .andExpect(jsonPath("$.feedback", CoreMatchers.is(messages.getMessage("http-proxies.intercept.failure"))))
// .andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(false)));
// }
@Test
public void whenPostAssignmentShouldNotPass() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.post("/HttpProxies/intercept-request")
.header("x-request-intercepted", "true")
.param("changeMe", "Requests are tampered easily"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.feedback", CoreMatchers.is(messages.getMessage("http-proxies.intercept.failure"))))
.andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(false)));
}
}

0 comments on commit c8ef848

Please sign in to comment.