fix: add input validation for Terraform state name parameter
What does this MR do and why?
This MR was created by Duo in Session 1102335
Changes
- Add input validation for Terraform state name parameter to prevent database constraint violations
- Implement proper length limits for state name field to match database schema constraints
- Add validation to prevent excessively long state names that cause ActiveRecord::ValueTooLong errors
Update:
Duo refused to push the changes after all
References
Screenshots or screen recordings
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
- Create a state name longer than 255 characters and make the API request:
bashcurl -X POST \
-H "Content-Type: application/json" \
-H "Private-Token: your-token-here" \
-d '{"ID":"test-lock","Operation":"OperationTypePlan","Info":"","Who":"test-user","Version":"1.0","Created":"2024-01-01T00:00:00Z","Path":""}' \
"https://gdk.test:3443/api/v4/projects/<project_id>/terraform/state/$(printf 'a%.0s' {1..300})/lock"
- Verify response returns HTTP 500 with database constraint error (before fix)
- Apply the fix and verify response returns HTTP 400 with "State name exceeds maximum length" message (after fix)
Edited by Anna Vovchenko

