WebOfTrust / keria

KERI Agent in the cloud
https://keria.readthedocs.io/en/latest/
Apache License 2.0
17 stars 26 forks source link

Internal Server Error on GET /identifiers/ (Trailing slash) #176

Closed lenkan closed 5 months ago

lenkan commented 5 months ago

Similar to #126. Keria responds with internal server error when doing a GET on path /identifiers/.

See reproduction script: https://github.com/lenkan/signify-ts/blob/fdc96e9b17b34b3e1de471d22a0ae19a186fe899/examples/integration-scripts/trigger-internal-server-error.test.ts

Stack trace:

keria-1  |   Agent: EHE0kCd6C5fNHPz6gzkMh--A8cXvoEpHhoQxrsU7I3XT   Controller: EG4u3zcVWk5fCN-p9NWu5w7yau5mGzyVdw_j2DPEpmiv
keria-1  | 2024-01-26 07:51:15 [FALCON] [ERROR] GET /identifiers/ => Traceback (most recent call last):
keria-1  |   File "/keria/venv/lib/python3.10/site-packages/keri/db/dbing.py", line 458, in getVal
keria-1  |     return(txn.get(key))
keria-1  | lmdb.BadValsizeError: mdb_get: MDB_BAD_VALSIZE: Unsupported size of key/DB name/data, or wrong DUPFIXED size
keria-1  |
keria-1  | During handling of the above exception, another exception occurred:
keria-1  |
keria-1  | Traceback (most recent call last):
keria-1  |   File "falcon/app.py", line 365, in falcon.app.App.__call__
keria-1  |   File "/keria/src/keria/app/aiding.py", line 446, in on_get
keria-1  |     hab = agent.hby.habByName(name)
keria-1  |   File "/keria/venv/lib/python3.10/site-packages/keri/app/habbing.py", line 788, in habByName
keria-1  |     elif (habord := self.db.habs.get(name)) is not None:
keria-1  |   File "/keria/venv/lib/python3.10/site-packages/keri/db/koming.py", line 281, in get
keria-1  |     return (self.deserializer(self.db.getVal(db=self.sdb,
keria-1  |   File "/keria/venv/lib/python3.10/site-packages/keri/db/dbing.py", line 460, in getVal
keria-1  |     raise KeyError(f"Key: `{key}` is either empty, too big (for lmdb),"
keria-1  | KeyError: "Key: `b''` is either empty, too big (for lmdb), or wrong DUPFIXED size. ref) lmdb.BadValsizeError"
keria-1  |

I believe we should do some input validation here and respond with a 4xx error. What do you think?

In my opinion, all these input validation issues are important before bumping to v1. For example, when you are monitoring KERIA in a production environment, you must be able to distinguish between actual internal server errors and client errors. Since we are using OpenAPI to some extent, most of the input validation can be generated using the json schemas.

lenkan commented 5 months ago

Same issue also when doing oobis().get('') with stack trace:

keria-1  |   Agent: EBZx2tc3vL9QqnLPbp1F8gu5XHazlX5HJ7o0ddIVsMSz   Controller: EIjF9At_rwAQtpPsXCOVhLsZ2gvInT29wRGbx54mOMGr
keria-1  | 2024-01-26 08:03:00 [FALCON] [ERROR] GET /identifiers//oobis?role=agent => Traceback (most recent call last):
keria-1  |   File "/keria/venv/lib/python3.10/site-packages/keri/db/dbing.py", line 458, in getVal
keria-1  |     return(txn.get(key))
keria-1  | lmdb.BadValsizeError: mdb_get: MDB_BAD_VALSIZE: Unsupported size of key/DB name/data, or wrong DUPFIXED size
keria-1  |
keria-1  | During handling of the above exception, another exception occurred:
keria-1  |
keria-1  | Traceback (most recent call last):
keria-1  |   File "falcon/app.py", line 365, in falcon.app.App.__call__
keria-1  |   File "/keria/src/keria/app/aiding.py", line 633, in on_get
keria-1  |     hab = agent.hby.habByName(name)
keria-1  |   File "/keria/venv/lib/python3.10/site-packages/keri/app/habbing.py", line 788, in habByName
keria-1  |     elif (habord := self.db.habs.get(name)) is not None:
keria-1  |   File "/keria/venv/lib/python3.10/site-packages/keri/db/koming.py", line 281, in get
keria-1  |     return (self.deserializer(self.db.getVal(db=self.sdb,
keria-1  |   File "/keria/venv/lib/python3.10/site-packages/keri/db/dbing.py", line 460, in getVal
keria-1  |     raise KeyError(f"Key: `{key}` is either empty, too big (for lmdb),"
keria-1  | KeyError: "Key: `b''` is either empty, too big (for lmdb), or wrong DUPFIXED size. ref) lmdb.BadValsizeError"
keria-1  |
pfeairheller commented 5 months ago

Closed with PR #178 that is in the 0.1.0 release candidate