TL;DR
Yes, GET requests in Spring Rest controllers can be intercepted and manipulated by attackers. While less common than attacks on POST/PUT/DELETE, they are still a risk. This guide explains how to protect your application using input validation, rate limiting, secure coding practices, and monitoring.
Understanding the Risks
GET requests send data in the URL. This makes them visible in browser history, server logs, and potentially proxies. Attackers can:
- Modify parameters: Change values to access unintended resources or perform unauthorized actions.
- Inject malicious code: Attempt SQL injection (less common with GET but possible), cross-site scripting (XSS) if the data is displayed without proper sanitisation.
- Replay requests: Capture and resend legitimate requests to bypass authentication or authorization checks.
Protecting Your Spring REST Controllers
- Input Validation – The First Line of Defence
- Validate all parameters: Never trust user input directly. Check data types, lengths, formats, and allowed values.
- Use annotations: Spring provides helpful validation annotations like
@NotNull,@Size,@Min,@Max, and@Pattern. - Example:
@RestController public class MyController { @GetMapping("/items") public ResponseEntity<List<Item>> getItems(@NotNull @Size(min = 1) String itemId) { // Validate itemId before processing... return ResponseEntity.ok(itemService.getItems(itemId)); } } - Rate Limiting – Prevent Abuse
- Limit requests per IP address/user: Protect against brute-force attacks and denial-of-service attempts.
- Spring Cloud Gateway or similar: Implement rate limiting at the gateway level for global protection.
- Example (using a simple in-memory map – not production ready):
import java.util.HashMap; import java.util.Map; // In your controller or a dedicated rate limiting component... private static final Map<String, Integer> requestCounts = new HashMap<>(); public ResponseEntity<Object> myEndpoint(String param) { String ipAddress = getClientIpAddress(); // Implement this method to get the client's IP. requestCounts.putIfAbsent(ipAddress, 0); int count = requestCounts.get(ipAddress) + 1; if (count > MAX_REQUESTS_PER_MINUTE) { return ResponseEntity.status(HttpStatus.TOO_MANY_REQUESTS).body("Too many requests"); } requestCounts.put(ipAddress, count); // Process the request... } - Secure Coding Practices
- Avoid displaying raw user input: Always encode output to prevent XSS attacks. Use a templating engine that automatically escapes HTML entities.
- Use prepared statements (if interacting with databases): Prevent SQL injection vulnerabilities, even with GET requests if data is used in database queries.
- Proper error handling: Avoid revealing sensitive information in error messages. Log errors securely and handle them gracefully.
- HTTPS – Encryption is Essential
- Always use HTTPS: Encrypt all communication between the client and server to protect data in transit.
- Redirect HTTP requests to HTTPS: Ensure that users are always using a secure connection.
- Monitoring and Logging – Detect Suspicious Activity
- Log all incoming requests: Include timestamps, IP addresses, URLs, parameters, and user agents.
- Monitor for unusual patterns: Look for excessive requests from a single IP address, unexpected parameter values, or other suspicious activity.
- Use security tools: Consider using web application firewalls (WAFs) to detect and block common attacks.
Important Considerations
- GET requests are idempotent: They should not have side effects. Avoid using GET requests for actions that modify data. Use POST, PUT, or DELETE instead.
- Sensitive Data in URLs: Never include sensitive information (passwords, API keys) directly in the URL of a GET request.

