vaultez-cli 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 824ab321c6ff7b03bd1495461f6c545bc15aa07d596c863e3388fc5d8383622f
4
- data.tar.gz: 5417e6a9394622242c58608eddd1186629dc63586fc9ba4545702e1168e8f5f3
3
+ metadata.gz: 78043da2b439dff80b3ed04f33ee62a77936276e5bd60935be94d2eca29592f0
4
+ data.tar.gz: aa76a4503506bd47d5e5b8a582725fbcee604bfdd0b23976e868e13bb7af2240
5
5
  SHA512:
6
- metadata.gz: 4d06a027b38872fb4b9e02ee827b03589d4ddffa9d8a0fbfca87fe00e71a5e7b64eedd63d48b5dbfcd9f4c5d195f3628bfaec74b4846a463a7b675721695e9e5
7
- data.tar.gz: 7808de1486e94c49eb163317f1d488de5e581fe83b1fc5dd9bf804d9d12d7a103401f2a59e6ad6c0ebb68f3b514f8539b4daf05dd7e143f63e905cf1fa435dea
6
+ metadata.gz: 1214dc2431ac95bac73be69ce5ed35a6bb1f854ebbdede1e011954bf6161e3031ef1a628f810ff531284fb228808a86f4d8a33df8bfab776c6d756d87c3dec5f
7
+ data.tar.gz: 1c9dcf449a65eeba1412ecae189f4d00cbae4cfe98437c7ed649a559b0868ad4f17e09090d92b6483a4d62c35154918dc738ae0695f4db8465cb251b1b62c8c9
@@ -4,6 +4,14 @@ require "uri"
4
4
 
5
5
  module Vaultez
6
6
  class Client
7
+ # A legitimate response (companies/projects/secrets, all short strings)
8
+ # is a handful of KB at most. This bounds how much of a compromised or
9
+ # malicious response - a compromised API backend, a MITM'd/redirected
10
+ # api_url, or a compromised account crafting an oversized payload - this
11
+ # process will hold in memory, independent of any size limit a caller
12
+ # (e.g. the oma-vaultez plugin) enforces on this CLI's own stdout.
13
+ MAX_RESPONSE_BYTES = 4 * 1024 * 1024
14
+
7
15
  def initialize
8
16
  @api_url = Vaultez::Config.api_url
9
17
  @token = Vaultez::Config.token
@@ -68,7 +76,9 @@ module Vaultez
68
76
  req.body = body.to_json if body
69
77
 
70
78
  begin
71
- response = http.request(req)
79
+ response = fetch_bounded(http, req)
80
+ rescue Vaultez::Error
81
+ raise
72
82
  rescue StandardError => error
73
83
  raise Vaultez::ApiError, "Could not reach the Vaultez API: #{error.message}"
74
84
  end
@@ -76,6 +86,27 @@ module Vaultez
76
86
  parse_response(response)
77
87
  end
78
88
 
89
+ # Reads the response body incrementally instead of Net::HTTP's default
90
+ # #request behavior, which fully buffers the entire body in memory
91
+ # before returning with no size limit at all. Aborts (closing the
92
+ # connection) the moment the body crosses MAX_RESPONSE_BYTES, rather
93
+ # than finishing the download and only noticing afterward.
94
+ def fetch_bounded(http, req)
95
+ response = nil
96
+ body = +""
97
+ http.request(req) do |res|
98
+ response = res
99
+ res.read_body do |chunk|
100
+ body << chunk
101
+ if body.bytesize > MAX_RESPONSE_BYTES
102
+ raise Vaultez::ApiError, "Vaultez API response exceeded the maximum allowed size"
103
+ end
104
+ end
105
+ end
106
+ response.body = body
107
+ response
108
+ end
109
+
79
110
  def build_request(method, uri)
80
111
  case method
81
112
  when :get then Net::HTTP::Get.new(uri)
@@ -1,3 +1,3 @@
1
1
  module Vaultez
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vaultez-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nur Ketene
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.6.9
61
+ rubygems_version: 4.0.16
62
62
  specification_version: 4
63
63
  summary: CLI tool for Vaultez — manage your secrets from the terminal
64
64
  test_files: []