Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/openai/internal/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,7 @@ class << self
y << "Content-Disposition: form-data"

unless key.nil?
name = ERB::Util.url_encode(key.to_s)
y << "; name=\"#{name}\""
y << "; name=\"#{key}\""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Escape multipart field names before writing Content-Disposition

Writing key directly into the quoted name parameter allows keys containing ", \, or CR/LF to break the Content-Disposition header syntax and potentially inject extra multipart headers/content when body keys are user-controlled. This line used to percent-encode keys, so the regression is introduced by this commit; even if [] should stay literal, the value still needs header-safe escaping (or CR/LF rejection) before interpolation.

Useful? React with 👍 / 👎.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this was a naive implementation. A safer fix would just be to unencode square brackets after url_encoding everything.

end

case val
Expand Down Expand Up @@ -577,7 +576,7 @@ class << self
case val
in Array if val.all? { primitive?(_1) }
val.each do |v|
write_multipart_chunk(y, boundary: boundary, key: key, val: v, closing: closing)
write_multipart_chunk(y, boundary: boundary, key: "#{key}[]", val: v, closing: closing)
end
else
write_multipart_chunk(y, boundary: boundary, key: key, val: val, closing: closing)
Expand Down