eschutho opened a new pull request, #43772:
URL: https://github.com/apache/superset/pull/43772
### SUMMARY
When configuring a new Google Sheets connection,
`GSheetsEngineSpec.validate_parameters` (`superset/db_engine_specs/gsheets.py`)
called `json.loads` on the client-supplied `service_account_info` string
**unguarded**:
```python
encrypted_credentials = parameters.get("service_account_info") or "{}"
if isinstance(encrypted_credentials, str):
encrypted_credentials = json.loads(encrypted_credentials) # <--
unguarded
```
That field arrives through `DatabaseValidateParametersSchema` as a free-form
`fields.Raw` value with no marshmallow-level JSON validation (unlike
`masked_encrypted_extra`, which is validated upstream via
`encrypted_extra_validator`). So a user pasting malformed or truncated JSON
into the "Service Account Credentials" field — a very plausible real-world typo
— made `json.loads` raise a raw `json.JSONDecodeError`.
#### PROBLEM
The exception propagated unclassified through the whole validate flow: `POST
/api/v1/database/validate_parameters/` → `DatabaseRestApi.validate_parameters`
→ `ValidateDatabaseParametersCommand.run()` →
`engine_spec.validate_parameters()`. None of these layers wrap the call, so the
raw `JSONDecodeError` reached Flask's global `@app.errorhandler(Exception)`
catch-all in `superset/views/error_handling.py` and surfaced as an opaque
**500** (`GENERIC_BACKEND_ERROR`) — instead of the **400**
`InvalidParametersError` that this validate-parameters flow exists to return
for user-fixable input.
#### FIX
Wrap the `json.loads` call in `try/except json.JSONDecodeError`. On failure,
append a `SupersetError` with
`error_type=SupersetErrorType.INVALID_PAYLOAD_FORMAT_ERROR` and
`level=ErrorLevel.ERROR` to the existing `errors` list and return early —
mirroring the existing early-return-on-fatal-validation-error pattern already
used in the same method (e.g. the "Sheet name is required" / "URL is required"
checks). The message clearly states the credentials field is not valid JSON.
This is a **pure additive catch** — no existing behavior changes for valid
input. The only behavioral change is intended: for malformed credentials the
endpoint now returns a **400** with a clear, field-scoped error instead of a
**500** opaque backend error. That is the fix, not a regression.
Same bug-class and pipeline as #42401 and #43725.
### TESTING INSTRUCTIONS
- New unit test `test_validate_parameters_malformed_credentials` in
`tests/unit_tests/db_engine_specs/test_gsheets.py` passes
`"service_account_info": "{not valid json"` and asserts `validate_parameters`
returns an `errors` list containing the `INVALID_PAYLOAD_FORMAT_ERROR`
`SupersetError` instead of raising.
- Verified empirically: on pre-fix code the same input raises
`simplejson.errors.JSONDecodeError`; post-fix it returns the errors list
cleanly.
- Full file: `pytest tests/unit_tests/db_engine_specs/test_gsheets.py` → 36
passed.
- `ruff check` and `ruff format --check` clean on both changed files.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]