Overview
The Product Distribution Dashboard API currently operates without authentication or authorization mechanisms. The API is designed for internal use within a controlled network environment and relies on CORS (Cross-Origin Resource Sharing) configuration to restrict access to approved frontend applications.Current Security Model
The API’s security model consists of:- CORS-based origin restriction: Only requests from the configured frontend URL are allowed
- Network-level security: API should be deployed in a private network or behind a firewall
- Input validation: Request parameters are validated using Jakarta Bean Validation
No Authentication Headers Required
API requests do not require any authentication headers such as:- API keys
- Bearer tokens
- Basic authentication credentials
- Session cookies
CORS Configuration
The API implements CORS to control which web applications can make requests to the backend.Configuration Details
CORS is configured in theCorsConfig class (backend/src/main/java/com/productdistribution/backend/config/CorsConfig.java:1):
CORS Settings
| Setting | Configuration | Description |
|---|---|---|
| Allowed Origins | ${app.frontend.url} | Only requests from this origin are permitted |
| Allowed Methods | GET, POST, OPTIONS | HTTP methods that can be used |
| Allowed Headers | * | All request headers are permitted |
| Mapped Paths | /** | CORS applies to all API endpoints |
| Allow Credentials | Not set (defaults to false) | Cookies and authentication headers not supported |
| Max Age | Not set | Browser caches preflight requests per default policy |
Frontend URL Configuration
The allowed frontend URL is configured via theapp.frontend.url property in application configuration files:
Development Environment
File:backend/src/main/resources/application-dev.properties:7
http://localhost:3000 or http://localhost:5173 for local development.
Production Environment
File:backend/src/main/resources/application-prod.properties:22
APP_FRONTEND_URL environment variable to the production frontend domain (e.g., https://app.example.com).
Environment Variable Setup
To configure the frontend URL, set theAPP_FRONTEND_URL environment variable:
The frontend URL must be an exact match. Subdomains, protocols, and ports must match exactly. For example,
http://localhost:3000 will not match http://localhost:3001.Making API Requests
From the Configured Frontend
Requests from the configured frontend application work automatically:CORS Preflight Requests
For non-simple requests (e.g., POST with JSON body), browsers automatically send a preflightOPTIONS request:
From Other Origins (Blocked)
Requests from origins other than the configured frontend URL will be blocked:Security Considerations
Current Limitations
- No user authentication: Cannot identify or verify users
- No authorization: All clients have full access to all endpoints
- No rate limiting: Susceptible to abuse and DoS attacks
- No audit logging: Cannot track who performed actions
- No API key validation: Cannot revoke access for specific clients
Recommended Deployment Practices
Given the lack of authentication, follow these deployment practices:- Private Network: Deploy the API in a private network not accessible from the public internet
- VPN/Firewall: Use VPN or firewall rules to restrict network access
- API Gateway: Place an API gateway with authentication in front of the API
- HTTPS Only: Always use HTTPS in production to encrypt data in transit
- Environment Isolation: Keep development and production environments separate
Data Validation
While authentication is absent, the API implements input validation:- Jakarta Bean Validation: Request parameters are validated (see
@Validannotations) - Type Safety: Strong typing prevents many injection attacks
- SQL Injection Protection: JPA/Hibernate provides parameterized queries
400 Bad Request with detailed error messages (see Error Handling).
Future Authentication Considerations
If authentication is implemented in the future, consider these approaches:Option 1: JWT Bearer Tokens
Implement JWT (JSON Web Token) authentication:- Stateless authentication
- Can include user roles and permissions
- Widely supported by frontend frameworks
- Add Spring Security with JWT support
- Update CORS config to handle
Authorizationheader - Implement token validation filter
Option 2: API Key Authentication
Use API keys for service-to-service authentication:- Simple to implement
- Easy to revoke individual keys
- Suitable for internal services
- Store API keys in database
- Add request filter to validate keys
- Provide key management endpoints
Option 3: OAuth 2.0 / OpenID Connect
Integrate with identity providers (Google, Azure AD, etc.): Advantages:- Enterprise-grade security
- Single sign-on (SSO) support
- Leverages existing identity infrastructure
- Add Spring Security OAuth2 client
- Configure identity provider
- Update frontend for OAuth flow
CORS Changes for Authentication
When implementing authentication, update CORS configuration:Testing Without Authentication
Using cURL
Test endpoints directly with cURL:cURL requests bypass CORS restrictions since CORS is a browser-enforced policy.
Using API Testing Tools
Tools like Postman, Insomnia, or Thunder Client can test the API without CORS restrictions:- Set the request URL (e.g.,
http://localhost:8080/api/products) - Choose the HTTP method (
GET,POST) - Send the request - no authentication headers needed
Browser Developer Tools
From the configured frontend application, use browser console:Troubleshooting CORS Issues
Issue: “CORS policy: No ‘Access-Control-Allow-Origin’ header”
Causes:- Frontend URL doesn’t match
app.frontend.urlconfiguration - Protocol mismatch (http vs https)
- Port mismatch
- Missing
APP_FRONTEND_URLenvironment variable
- Verify
APP_FRONTEND_URLenvironment variable is set correctly - Check application logs for configured frontend URL
- Ensure exact match including protocol and port
- Restart backend after configuration changes
Issue: “Method not allowed”
Cause: Using HTTP method not in allowed list (PUT, DELETE, PATCH)
Solution: Only GET, POST, and OPTIONS are allowed. Use supported methods or update CorsConfig.
Issue: “Credentials mode is ‘include’”
Cause: Frontend sending credentials butallowCredentials not enabled
Solution: Either:
- Remove credentials from frontend request
- Add
.allowCredentials(true)to CORS config
Related Resources
API Overview
Return to API overview and available endpoints
Configuration
Learn about backend configuration options
Error Handling
Understand error response formats
Deployment
Backend deployment guide and security setup