Commit 3624e4e
`URI.open` is not safe because it can execute commands like those shown below:
```console
$ ruby -ropen-uri -e 'p URI.open(%q{| echo "hi"}).read'
"hi\n"
```
Replacing it with `URI.parse#open`, as already used in `Langchain::Loader`, makes it more secure:
https://github.com/patterns-ai-core/langchainrb/blob/0.19.5/lib/langchain/loader.rb#L95
```console
$ ruby -ropen-uri -e 'p URI.parse(%q{| echo "hi"}).open.read'
/Users/koic/.rbenv/versions/3.4.3/lib/ruby/gems/3.4.0/gems/uri-1.0.3/lib/uri/rfc3986_parser.rb:130:
in 'URI::RFC3986_Parser#split': bad URI (is not URI?): "| echo \"hi\"" (URI::InvalidURIError)
from /Users/koic/.rbenv/versions/3.4.3/lib/ruby/gems/3.4.0/gems/uri-1.0.3/lib/uri/rfc3986_parser.rb:135:
in 'URI::RFC3986_Parser#parse'
from /Users/koic/.rbenv/versions/3.4.3/lib/ruby/gems/3.4.0/gems/uri-1.0.3/lib/uri/common.rb:212:in 'URI.parse'
from -e:1:in '<main>'
```
It likely makes sense also in terms of reusing the parsed `uri` object.
Co-authored-by: Andrei Bondarev <andrei@sourcelabs.io>
1 parent dd29cdc commit 3624e4e
File tree
2 files changed
+6
-2
lines changed- lib/langchain/utils
- spec/langchain/utils
2 files changed
+6
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
0 commit comments