Skip to content

Commit 803279a

Browse files
authored
Add option to disable host validation. (#129)
1 parent 8d45ffa commit 803279a

5 files changed

+29
-8
lines changed

ESPWebThingAdapter.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343

4444
class WebThingAdapter {
4545
public:
46-
WebThingAdapter(String _name, IPAddress _ip, uint16_t _port = 80)
47-
: server(_port), name(_name), ip(_ip.toString()), port(_port) {}
46+
WebThingAdapter(String _name, IPAddress _ip, uint16_t _port = 80,
47+
bool _disableHostValidation = false)
48+
: server(_port), name(_name), ip(_ip.toString()), port(_port),
49+
disableHostValidation(_disableHostValidation) {}
4850

4951
void begin() {
5052
name.toLowerCase();
@@ -197,12 +199,17 @@ class WebThingAdapter {
197199
String name;
198200
String ip;
199201
uint16_t port;
202+
bool disableHostValidation;
200203
ThingDevice *firstDevice = nullptr;
201204
ThingDevice *lastDevice = nullptr;
202205
char body_data[ESP_MAX_PUT_BODY_SIZE];
203206
bool b_has_body_data = false;
204207

205208
bool verifyHost(AsyncWebServerRequest *request) {
209+
if (disableHostValidation) {
210+
return true;
211+
}
212+
206213
AsyncWebHeader *header = request->getHeader("Host");
207214
if (header == nullptr) {
208215
request->send(403);

EthernetWebThingAdapter.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ enum ReadState {
7373

7474
class WebThingAdapter {
7575
public:
76-
WebThingAdapter(String _name, uint32_t _ip, uint16_t _port = 80)
77-
: name(_name), port(_port), server(_port)
76+
WebThingAdapter(String _name, uint32_t _ip, uint16_t _port = 80,
77+
bool _disableHostValidation = false)
78+
: name(_name), port(_port), server(_port),
79+
disableHostValidation(_disableHostValidation)
7880
#ifdef CONFIG_MDNS
7981
,
8082
mdns(udp)
@@ -240,6 +242,7 @@ class WebThingAdapter {
240242
private:
241243
String name, ip;
242244
uint16_t port;
245+
bool disableHostValidation;
243246
EthernetServer server;
244247
EthernetClient client;
245248
#ifdef CONFIG_MDNS
@@ -260,6 +263,10 @@ class WebThingAdapter {
260263
ThingDevice *firstDevice = nullptr, *lastDevice = nullptr;
261264

262265
bool verifyHost() {
266+
if (disableHostValidation) {
267+
return true;
268+
}
269+
263270
int colonIndex = host.indexOf(':');
264271
if (colonIndex >= 0) {
265272
host.remove(colonIndex);

WiFi101WebThingAdapter.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ enum ReadState {
6767

6868
class WebThingAdapter {
6969
public:
70-
WebThingAdapter(String _name, uint32_t _ip, uint16_t _port = 80)
71-
: name(_name), port(_port), server(_port), mdns(udp) {
70+
WebThingAdapter(String _name, uint32_t _ip, uint16_t _port = 80,
71+
bool _disableHostValidation)
72+
: name(_name), port(_port), server(_port),
73+
disableHostValidation(_disableHostValidation), mdns(udp) {
7274
ip = "";
7375
for (int i = 0; i < 4; i++) {
7476
ip += _ip & 0xff;
@@ -228,6 +230,7 @@ class WebThingAdapter {
228230
private:
229231
String name, ip;
230232
uint16_t port;
233+
bool disableHostValidation;
231234
WiFiServer server;
232235
WiFiClient client;
233236
WiFiUDP udp;
@@ -246,6 +249,10 @@ class WebThingAdapter {
246249
ThingDevice *firstDevice = nullptr, *lastDevice = nullptr;
247250

248251
bool verifyHost() {
252+
if (disableHostValidation) {
253+
return true;
254+
}
255+
249256
int colonIndex = host.indexOf(':');
250257
if (colonIndex >= 0) {
251258
host.remove(colonIndex);

library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "webthing-arduino",
33
"description": "A library for creating Web Things using the Web of Things API. Runs on ESP8266, ESP32, Ethernet, and WiFi101-compatible boards. Compatible with the WebThings Gateway.",
44
"keywords": "Communication",
5-
"version": "0.11.7",
5+
"version": "0.12.0",
66
"authors": {
77
"name": "WebThingsIO",
88
"email": "[email protected]",

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=webthing-arduino
2-
version=0.11.7
2+
version=0.12.0
33
author=WebThingsIO <[email protected]>
44
maintainer=WebThingsIO <[email protected]>
55
sentence=A library for creating Web Things using the Web of Things API

0 commit comments

Comments
 (0)