Skip to content

Commit

Permalink
Extend headers validation pattern (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyBitz authored Jan 24, 2023
1 parent 9362fd2 commit 36f4b63
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deployment/config-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = {
type: 'string',
minLength: 1,
maxLength: 2048,
pattern: "^[a-zA-Z0-9_!#$%&'*+.;/:, =^`|~-]+$"
pattern: '^[\u0020-\u007e\u00a0-\u00ff]+$'
}
},
additionalProperties: false
Expand Down
43 changes: 43 additions & 0 deletions test/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ exports.test_valid_static_headers_object = () => {
});

assert.equal(isValid, true);

for (let i = 0x20; i <= 0xff; i++) {
if (i > 0x7e && i < 0xa0) {
continue;
}

const result = ajv.validate(deploymentConfigSchema, {
'static': {
headers: [
{
source: '/',
headers: [{
key: 'X-Test',
value: `value ${String.fromCharCode(i)}`
}]
}
]
}
});

assert.equal(result, true, `Failed to validate for char: 0x${i.toString(16)}`);
}
};

exports.test_invalid_static_headers_object = () => {
Expand All @@ -206,6 +228,27 @@ exports.test_invalid_static_headers_object = () => {
});

assert.equal(isValid, false);

// Use 256 to go above 0xff
for (let i = 0; i <= 256; i++) {
if ((i >= 0x20 && i <= 0x7e) || (i >= 0xa0 && i <= 0xff)) {
continue;
}

const result = ajv.validate(deploymentConfigSchema, {
'static': {
headers: {
source: '/',
headers: [{
key: 'X-Test',
value: `value ${String.fromCharCode(i)}`
}]
}
}
});

assert.equal(result, false, `Failed to error for char: 0x${i.toString(16)}`);
}
};

exports.test_valid_static_object_trailing_slash = () => {
Expand Down

0 comments on commit 36f4b63

Please sign in to comment.