Skip to content
Open
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion src/node_http_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ using v8::Isolate;
using v8::Local;
using v8::LocalVector;
using v8::MaybeLocal;
using v8::NewStringType;
using v8::Number;
using v8::Object;
using v8::ObjectTemplate;
Expand Down Expand Up @@ -233,6 +234,17 @@ struct StringPtr {
return String::Empty(env->isolate());
}

Local<String> ToInternalizedString(Environment* env) const {
if (size_ != 0) {
return String::NewFromOneByte(env->isolate(),
reinterpret_cast<const uint8_t*>(str_),
NewStringType::kInternalized,
size_)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm.. I'm not convinced this is a good idea.

While it certainly helps legitimate cases, there's a risk here.

A malicious sender could leverage this into a memory leak or cause significant additional GC pressure pretty easily by sending a large number of intentionally different header values at a high rate. Internalized strings do get cleaned up during a major GC. The current existing non-internalized strings can be cleaned up in a minor GC.

We really ought to be internalizing only known header names.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You're right, should I apply the same fix on the HTTP/2 path?

name_.reset(name, true); // Internalizable

.ToLocalChecked();
}
return String::Empty(env->isolate());
}
Comment thread
araujogui marked this conversation as resolved.

// Strip trailing OWS (SPC or HTAB) from string.
Local<String> ToTrimmedString(Environment* env) {
while (size_ > 0 && IsOWS(str_[size_ - 1])) {
Expand Down Expand Up @@ -940,7 +952,8 @@ class Parser : public AsyncWrap, public StreamListener {
Local<Value> headers_v[kMaxHeaderFieldsCount * 2];

for (size_t i = 0; i < num_values_; ++i) {
headers_v[i * 2] = fields_[i].ToString(env());
// Field names repeat across requests, so internalize them.
headers_v[i * 2] = fields_[i].ToInternalizedString(env());
headers_v[i * 2 + 1] = values_[i].ToTrimmedString(env());
}

Expand Down
Loading