Open keymandll opened 2 years ago
Anyone got a pull request? This library has been going for donkeys years without this, so that suggests people are sanetizing their own inputs, but if you need the library to make it safe by default I'd really appreciate a pull request.
I make absolutely nothing from this and its taking time out of tree planting or paid work, time I don't have.
The way we mitigated it (canRead: ['.yml', '.json']
mentioned above) works perfectly fine for us, given there are no other yml
or json
documents with sensitive info around, just the ones we feed to the library for processing.
Similarly to you, I do not have much time, so I thought I'd only put together a pull request if there was significant demand. It seems so far no one cared.
One thing I could do in the upcoming days is to submit a PR with an updated README to let people know about this behaviour.
P.s.: Thanks a lot for this library.
That would be great! Letting people know they can do that is handy, and it avoids the issue of disabling it by default and causing issues for people who $ref URLs that might not have extensions in (I've seen that done).
The related pull request: https://github.com/APIDevTools/swagger-parser/pull/236
I have noticed that by default the library (tested with version
10.1.0
) is willing to resolve just any files pointed to by$ref
. This can be a problem if the library is used by something that:For example, given the below OpenAPI document
If we just do the below
We will get (showing just a snippet of the processed document to keep it short):
I have checked the different configuration options available and I found that things can be somewhat mitigated by configuring the file resolver as shown below.
In this case, the library is only willing to work with
yml
andjson
files, giving this result:At the same time, it is still possible to get any JSON or YAML files opened on the file system. Someone malicious could use this to gain access to sensitive data (e.g. credentials) in JSON or YAML files if:
server
specified in the OpenAPI docAs can be seen, there are plenty of ifs, but depending on the use case things can get problematic.
My recommendation would be (without intimately being familiar with the library) to:
options.resolve.file.canRead
set to['.yml', '.yaml', '.json']
by default. I mean, this should be the default behavior.options.resolve.file.basePath
that allows defining a path from which the library is willing to load/resolve files. The library would refuse to load/resolve any files outside of the specified directory or directories.