Skip to content
Open
Show file tree
Hide file tree
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: 5 additions & 0 deletions src/lib/isFQDN.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export default function isFQDN(str, options) {
str = str.substring(2);
}

/* Presentation-form FQDN max length is 253 (RFC 1035 / RFC 3696). */
if (!options.ignore_max_length && str.length > 253) {
return false;
}

const parts = str.split('.');
const tld = parts[parts.length - 1];

Expand Down
27 changes: 27 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,33 @@ describe('Validators', () => {
],
});
});
it('should reject FQDNs longer than 253 characters unless ignore_max_length is set', () => {
const label = 'a'.repeat(63);
// Each label stays within the 63-char limit; only the overall length differs.
const atLimit = [label, label, label, 'a'.repeat(57), 'com'].join('.'); // 253
const tooLongByOne = [label, label, label, 'a'.repeat(58), 'com'].join('.'); // 254
const tooLong = [label, label, label, label, 'comm'].join('.'); // 260
test({
validator: 'isFQDN',
valid: [
atLimit,
],
invalid: [
tooLongByOne,
tooLong,
],
});
test({
validator: 'isFQDN',
args: [
{ ignore_max_length: true },
],
valid: [
tooLongByOne,
tooLong,
],
});
});
it('should validate FQDN with trailing dot option', () => {
test({
validator: 'isFQDN',
Expand Down
22 changes: 22 additions & 0 deletions test/validators/isFQDN.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,26 @@ describe('isFQDN', () => {
],
});
});

it('should enforce the 253-character domain length limit', () => {
const label = 'a'.repeat(63);
const atLimit = [label, label, label, 'a'.repeat(57), 'com'].join('.');
const tooLong = [label, label, label, label, 'comm'].join('.');
test({
validator: 'isFQDN',
valid: [
atLimit,
],
invalid: [
tooLong,
],
});
test({
validator: 'isFQDN',
args: [{ ignore_max_length: true }],
valid: [
tooLong,
],
});
});
});
Loading