Handling untrusted input¶
X12 files carry protected health information, and the files a service receives come from someone else: trading partners, uploads, AI assistants. This page lists what x12sdk does to make such input safe, and the few things your code has to do.
What you need to do¶
Turn off file paths for input you did not create. For convenience, every
reading function accepts either X12 text or a path to an X12 file. When the
string comes from someone else, a path would let them make your service read a
file on its own disk, such as another customer’s claims. Pass
allow_paths=False, and the string is only ever read as X12 text:
from x12sdk.generate import generate_835
from x12sdk.io import X12ModelReader
from x12sdk.tables import read_lines
from x12sdk.validation import check
uploaded = generate_835(seed=1, claims=2) # stands in for a request body
with X12ModelReader(uploaded, allow_paths=False) as reader:
models = list(reader.models())
rows = read_lines(uploaded, allow_paths=False)
result = check(uploaded, allow_paths=False)
X12ModelReader, X12SegmentReader, iter_lines, read_lines,
to_dataframe, write_csv, match_claims, match_rows and check all
accept it. With paths off, check gives the same answer for a path that
exists and one that does not, so it cannot be used to probe your disk. The MCP
server and the browser playground always read text only.
Keep raw exceptions out of user-facing responses. x12sdk keeps file
content out of its own error messages (see below). Still, turn errors into a
response with check() or
problems(), which report where a file breaks and
why, rather than sending a traceback.
What x12sdk does for you¶
Risk |
Protection |
|---|---|
Reading files named in the input |
|
PHI in error messages and logs |
Validation errors never quote the rejected value. |
Injection when writing X12 |
Writing refuses any value that contains the segment terminator or element separator, which would otherwise end the element early and let the rest be read as new elements or segments. Composite and repeating elements also refuse the component and repetition separators. The error names the field, not the value. |
Formulas in CSV output |
|
Numbers that exhaust memory |
Decimal elements must be plain X12 decimals of at most 18 digits. |
Confusing delimiters |
An interchange whose delimiters repeat, or are letters, digits or spaces, is rejected. |
Choosing what is imported |
The transaction set code (ST01) and version (GS08/ST03) pick the parser module. Both are checked against the sets the library supports before anything is imported. |
Oversized generator calls from an AI assistant |
The MCP server’s generators make at most 10,000 claims, members or patients per call. |
The test suite checks each of these in src/tests/test_untrusted_input.py,
including a run that replaces every element of every segment with a marker
and asserts the marker never appears in an error.
Reporting a vulnerability¶
Please report security problems privately, through GitHub’s private vulnerability reporting, not in a public issue. The security policy says what to include and what happens next.