-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime check for string type doesn't check instanceof String
#112746
Comments
Pinging @elastic/kibana-core (Team:Core) |
notes for the Core team: there is no kibana/src/core/server/saved_objects/serialization/serializer.ts Lines 87 to 88 in 9b410ce
TODO: check seralization / deseralization logic in @elastic/elasticsearch client.
|
Well off the cuff, if this is reproducible locally, I'd be curious what I did not inspect the call site, but given that most of the parameters of Just an idea. Years ago, as a Java dev, I've seen that happen. |
@pmuellr maybe we can start with improving the error message to include a type of import typeDetect from 'type-detect';
function assertNonEmptyString(value: string, name: string) {
if (!value) {
throw new TypeError(`Expected ${name} to be a non-empty string but given ${value}`);
}
if (typeof value !== 'string') {
throw new TypeError(`Expected ${name} to be a string but given ${typeDetect(value)}`);
}
} |
Ya, was thinking that something like that might be good. Will at least call out what type of object it actually was. |
A little more info from the case that spawned this issue (SDH referenced ^^^). At one point the user tried using the saved object HTTP APIs to do some kind of searches, and was getting a 500 response back from Kibana. I've requested a dump of the |
Yea, that's my feeling too, especially given this specific issue seems like a (very) isolated case. |
I think we found the source of the original problem. The user that reported a rule saved object that was saved in Is there any known way that could happen? And so this is fun, turns out if > s = 'sss'
'sss'
> `-${s}-`
'-sss-'
> `-${[s]}-`
'-sss-' Perhaps the "proper" fix for this is to do a super-simple validation for the "top-level" SO properties and ensure they are the type they are expected to be. |
Type is stored in
#115175 will highlight the problem on "read" operation but agree we shouldn't accept an invalid object on a "write". cc @rudolf @pgayvallet |
#115175 was merged a while ago now, and we never re-encountered such problem on any other deployment. I'll go ahead and close this. |
Kibana version: 7.14.1
We're seeing an odd case of a user getting the following messages logged:
We think this is coming from the following code, and we're guessing that somehow the
value
in this case could be aString()
object vs the usualstring
type. We're not sure how that could happen.Update: it wasn't a
String()
object, it was an array of strings! see: #112746 (comment)kibana/src/core/server/saved_objects/serialization/serializer.ts
Lines 182 to 190 in 8cf0efe
kibana/src/core/server/saved_objects/serialization/serializer.ts
Lines 237 to 241 in 8cf0efe
The error we're seeing is rooted at a health check task (a task manager task) we have that runs every hour, starting here:
kibana/x-pack/plugins/alerting/server/health/task.ts
Lines 65 to 92 in 8cf0efe
That code will eventually call the code in https://github.com/elastic/kibana/blob/master/x-pack/plugins/alerting/server/health/get_health.ts, which appears to reference the
alert
string as a literal string, so ... not sure what could have happened. Build error? Or maybe I'm not looking at the right thing.So, this is super-weird, seems hard to believe what we're seeing actually :-), but figured I'd report it.
If this ends up being a real issue (strings can morph to Strings), then we'll need to arrange to do better "string validation", by checking for
instanceof String
or such. A quick VSCode search through Kibana oftypeof.*'string'
yielded 777 hits over 525 files.The text was updated successfully, but these errors were encountered: