Closed AyaMorisawa closed 2 years ago
おそらく原因はundefinedチェックをしていないため。
(もう?) 起きない? ちゃんと返ってくる
$ curl -v -w '\n' -H 'Content-Type: application/json' -d '' http://host/api/notes/show
> POST /api/notes/show HTTP/1.1
> Host: host
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 0
>
< HTTP/1.1 400 Bad Request
< Vary: Accept-Encoding, Origin
< Cache-Control: private, max-age=0, must-revalidate
< Content-Type: application/json; charset=utf-8
< Content-Length: 84
< Date: Tue, 25 Dec 2018 11:51:33 GMT
< Connection: keep-alive
<
{"error":{"code":"INVALID_PARAM","param":"noteId","reason":"must-be-not-undefined"}}
いいえ、虚無とは{}
のことで、現在もおきます。この場合、
https://github.com/syuilo/misskey/blob/89ac15b4de53770df661ef494b2c56220ff69b1a/src/server/api/call.ts#L54
のapp
にそのまま{}
が渡されるため、各所でエラーが発生するようです。
いや起きない
$ curl -v -w '\n' -H 'Content-Type: application/json' -d '{}' http://host/api/notes/show
> POST /api/notes/show HTTP/1.1
> Host: host
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 2
>
< HTTP/1.1 400 Bad Request
< Vary: Accept-Encoding, Origin
< Cache-Control: private, max-age=0, must-revalidate
< Content-Type: application/json; charset=utf-8
< Content-Length: 84
< Date: Tue, 25 Dec 2018 11:55:15 GMT
< Connection: keep-alive
<
{"error":{"code":"INVALID_PARAM","param":"noteId","reason":"must-be-not-undefined"}}
自環境だと起きる……
<-- POST /api/users/show
TypeError: Cannot read property 'toLowerCase' of undefined
at Promise (/Users/acid-chicken/misskey/built/server/api/endpoints/users/show.js:64:48)
at new Promise (<anonymous>)
at exports.default.define_1.default (/Users/acid-chicken/misskey/built/server/api/endpoints/users/show.js:38:62)
at Object.exec (/Users/acid-chicken/misskey/built/server/api/define.js:17:16)
at Promise (/Users/acid-chicken/misskey/built/server/api/call.js:43:24)
at new Promise (<anonymous>)
at Object.exports.default (/Users/acid-chicken/misskey/built/server/api/call.js:6:56)
at exports.default (/Users/acid-chicken/misskey/built/server/api/api-handler.js:34:35)
at process.internalTickCallback (internal/process/next_tick.js:77:7)
% curl -v -w '\n' -H 'Content-Type: application/json' -d '{}' http://localhost:3000/api/users/show
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3000 (#0)
> POST /api/users/show HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 2
>
* upload completely sent off: 2 out of 2 bytes
あーparamのValidate依存
この場合パラメータのバリデーションはちゃんと通過しているみたい たぶんendpoint固有の問題だと思う
バリデーションではuserId
かusername
はどちらも未定義であることを許容しているけど
使用しているときにはuserId
とusername
の両方が未定義であることを想定してないので
username
でエラーが出る
https://github.com/syuilo/misskey/blob/fa03c172f211f84dd9747fcf312ec41a92d1102b/src/server/api/endpoints/users/show.ts#L66-L68
なるほど。
では両方undefined
ならばエラーにする処理入れれば良さそうですね
なるほど。 では両方
undefined
ならばエラーにする処理入れれば良さそうですね
可能であればバリデーションの強化か、オーバーロードへの対応などをした方が良さそう。
バリデーションの合否を他のバリデーションに依存させるのは若干実装が複雑になりそうな感じはしますね
ではオーバーロードにしませんか。見た目が非常に良くなると思います。
めっちゃ古いIssueを見つけたのですが、さすがに直ってますよね…?
まだ残ってる
API console は JSON以外のものを入れるとクライアント側でエラーになるのでそれは別のエラー
SyntaxError: JSON5: invalid end of input at 1:1
ちゃんと users/show
はエラー返す
$ curl -w '\n' -H 'Content-Type: application/json' -d '{}' https://misskey.io/api/users/show
{"error":{"message":"Internal error occurred. Please contact us if the error persists.","code":"INTERNAL_ERROR","id":"5d37dbcb-891e-41ca-a3d6-e690c97775ac","kind":"server","info":{"e":{"message":"Cannot read property 'toLowerCase' of undefined","code":"TypeError","stack":"TypeError: Cannot read property 'toLowerCase' of undefined\n at /misskey/built/server/api/endpoints/users/show.js:91:48\n at Object.exec (/misskey/built/server/api/define.js:22:16)\n at Object.exports.default (/misskey/built/server/api/call.js:64:21)\n at /misskey/built/server/api/api-handler.js:26:23\n at runMicrotasks (<anonymous>)\n at processTicksAndRejections (internal/process/task_queues.js:93:5)"}}}}
他のエンドポイントがどうかはわからん
APIでなにか起きると何も返ってこないのは https://github.com/syuilo/misskey/commit/2756f553c68082342a784ef716c62da6cea6f3ca でなおってるはず
どれかのパラメーターが必要だけどパラメーターエラーにしてくれないエンドポイントは結構ある users/show {} => INTERNAL_ERROR が返るけど INVALID_PARAM を返して欲しい pages/show {} => NO_SUCH_PAGE が返るけど INVALID_PARAM を返して欲しい :
https://misskey.xyz/notes/5b5ab8e040c98369543c4422