AlinsRan opened a new pull request, #13886:
URL: https://github.com/apache/apisix/pull/13886

   ### Description
   
   Five defects in the standalone declarative-configuration paths, found while 
exercising the Admin API added by #13483. Each was reproduced before it was 
fixed, and each has a test that fails on master.
   
   **`validate_configuration()` trusts the shape of the request body.** It 
assumes the body is a table and that every resource list is an array. Neither 
holds for client-supplied input:
   
   - `{"routes": "not-an-array"}` gives `#items == 3`, then `ipairs` raises.
   - `core.json.decode("123")` returns a scalar without an error, which is then 
indexed.
   
   `POST /apisix/admin/configs/validate` turns that into a confusing 400 
through its `pcall`, but `apisix/admin/standalone.lua` calls the same function 
without one, so `PUT /apisix/admin/configs` answers 500 instead of rejecting 
the input.
   
   **The same handler logs the whole request body when parsing fails.** That 
body is a full declarative configuration and can carry `key-auth.key`, 
`jwt-auth.secret`, `basic-auth.password` and TLS private keys, so one malformed 
push writes them to the error log in plaintext. It now logs the parser error 
only.
   
   **`admin/stream_routes.lua` skips the self-reference check during standalone 
validation.** The `superior_id == id` check sits inside the 
`skip_references_check` gate, so a stream route naming itself as its own 
superior passes validation. That check needs no etcd lookup; only the fetch 
below it does, so it moves outside the gate.
   
   **`cli/file.lua` and `cli/ops.lua` index deployment sections without a 
guard.** Writing `role_traditional:` or `admin:` as YAML null makes 
`merge_conf` drop the default table, and `apisix init` then dies with a Lua 
stack trace where it should print a configuration error. The lines immediately 
around the one in `ops.lua` already guard the same table:
   
   ```
   $ printf 'apisix:\n  node_listen: 9080\ndeployment:\n  role: traditional\n  
role_traditional:\n' > conf/config.yaml
   $ make init
   ... apisix/cli/file.lua:293: attempt to index field 'role_traditional' (a 
nil value)
   ```
   
   ### Which issue(s) this PR fixes
   
   No open issue; found while working on the standalone Admin API.
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [x] I have explained the changes or the new features added to this PR
   - [x] I have added tests corresponding to this change
   - [x] I have updated the documentation to reflect this change — not 
applicable, no user-facing interface changes
   - [x] I have verified that this change is backward compatible — the only 
behavior changes are rejecting input that previously raised, and no longer 
logging the body


-- 
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]

Reply via email to