Skip to content

Commit 36f4b63

Browse files
authored
Extend headers validation pattern (#76)
1 parent 9362fd2 commit 36f4b63

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

deployment/config-static.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = {
4949
type: 'string',
5050
minLength: 1,
5151
maxLength: 2048,
52-
pattern: "^[a-zA-Z0-9_!#$%&'*+.;/:, =^`|~-]+$"
52+
pattern: '^[\u0020-\u007e\u00a0-\u00ff]+$'
5353
}
5454
},
5555
additionalProperties: false

test/deployment.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,28 @@ exports.test_valid_static_headers_object = () => {
181181
});
182182

183183
assert.equal(isValid, true);
184+
185+
for (let i = 0x20; i <= 0xff; i++) {
186+
if (i > 0x7e && i < 0xa0) {
187+
continue;
188+
}
189+
190+
const result = ajv.validate(deploymentConfigSchema, {
191+
'static': {
192+
headers: [
193+
{
194+
source: '/',
195+
headers: [{
196+
key: 'X-Test',
197+
value: `value ${String.fromCharCode(i)}`
198+
}]
199+
}
200+
]
201+
}
202+
});
203+
204+
assert.equal(result, true, `Failed to validate for char: 0x${i.toString(16)}`);
205+
}
184206
};
185207

186208
exports.test_invalid_static_headers_object = () => {
@@ -206,6 +228,27 @@ exports.test_invalid_static_headers_object = () => {
206228
});
207229

208230
assert.equal(isValid, false);
231+
232+
// Use 256 to go above 0xff
233+
for (let i = 0; i <= 256; i++) {
234+
if ((i >= 0x20 && i <= 0x7e) || (i >= 0xa0 && i <= 0xff)) {
235+
continue;
236+
}
237+
238+
const result = ajv.validate(deploymentConfigSchema, {
239+
'static': {
240+
headers: {
241+
source: '/',
242+
headers: [{
243+
key: 'X-Test',
244+
value: `value ${String.fromCharCode(i)}`
245+
}]
246+
}
247+
}
248+
});
249+
250+
assert.equal(result, false, `Failed to error for char: 0x${i.toString(16)}`);
251+
}
209252
};
210253

211254
exports.test_valid_static_object_trailing_slash = () => {

0 commit comments

Comments
 (0)