Skip to content

Isbn accepts any EAN-13 barcode: Isbn.Create("4006381333931") (a non-book product code) validates because the 978/979 prefix is never checked #334

Closed

Description

@matt-edmondson

What's wrong

The ISBN-13 branch of IsIsbnAttribute checks that the value has 13 digits and a valid mod-10 check digit. It checks nothing else:

if (value.Length == 13 && IsValidIsbn13(value))
{
return ValidationResult.Success();
}

private static bool IsValidIsbn13(string s)
{
int sum = 0;
for (int i = 0; i < 13; i++)
{
char c = s[i];
if (c is < '0' or > '9')
{
return false;
}
int d = c - '0';
sum += ((i % 2) == 0) ? d : (d * 3);
}
return (sum % 10) == 0;
}

That is the EAN-13 check, and every retail barcode passes it. An ISBN-13 is an EAN-13 in the "Bookland" range, which means it must begin with the GS1 prefix 978 or 979. The type's docs say that "registration-group and publisher ranges are not validated". That limitation applies to the groups inside an ISBN. The prefix is what makes a 13-digit code an ISBN in the first place, and it needs no range table.

Reproduction (run against the built assembly, HEAD 4d5ec8d)

Isbn.Create("4006381333931"); // accepted: EAN of a retail product, not a book
Isbn.Create("1234567890128"); // accepted: arbitrary 12 digits + a valid check digit

Any check-digit-valid 13-digit number is therefore an Isbn. That includes most barcodes a scanner returns, so a type meant to tell a book identifier apart from other strings does not.

Suggested fix / acceptance criteria

  • In the 13-character branch, require s.StartsWith("978", StringComparison.Ordinal) || s.StartsWith("979", StringComparison.Ordinal) before the checksum.
  • Update the XML docs on Isbn / IsIsbnAttribute to state the prefix rule.
  • Tests in Semantics.Test/Identifiers/IsbnTests.cs: 4006381333931 and 1234567890128 throw ArgumentException. 978-0-306-40615-7 still validates, and a valid 979- ISBN (e.g. 979-10-90636-07-1) validates.

Activity

  1. added
    bug
    on Sep 29, 2026
  2. matt-edmondson commented on Sep 29, 2026

    @matt-edmondson
    ContributorAuthor

    Triage

    • Category: Bug
    • Priority: Medium. Isbn accepts any EAN-13 barcode, so the type doesn't tell book identifiers apart from other codes. The fix is a one-line prefix check plus tests. Tightening validation may reject values that callers already store, so mention it in the release notes.
    • Area: Semantics.Strings.Identifiers (IsIsbnAttribute)
    • Suggested assignment: Semantics.Strings maintainer
    • Duplicates / in progress: none found

    Generated by Claude Code

  3. added a commit that references this issue on Oct 14, 2026
    74cf632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions