feat:implement APTS-MR-024: Final LLM Output Sanitization and Validation - #72
feat:implement APTS-MR-024: Final LLM Output Sanitization and Validation#72rashim27us wants to merge 3 commits into
Conversation
|
@ossumpossum looping you in, in case you wanted to review this. :) |
|
@rashim27us in the meantime, two spots in MR-A04's own body use capitalized MUST/SHOULD (the Practice Description intro, and item 2). Every other advisory uses lowercase modals or plain imperative phrasing in its own text, since RFC 2119 casing is reserved for actual normative requirements. Could you lowercase both? |
|
Went a bit past just the dispatch-boundary wording since I was in the file. Flag if you'd rather I split the SSRF stuff into a separate issue. Double-checked against primary sources / the actual repo:
One real gap in Tested it against a few known SSRF bypass patterns. Even as illustrative example code rather than a hardened reference impl, this is going to get copied verbatim, so worth closing: Root cause is that it's a hostname string match with no resolution behind it, so beyond the specific ranges above, it's also open to plain DNS rebinding: Something like this closes the cases above (tested against all of them, plus a couple of ordinary external domains to make sure nothing legitimate gets blocked): import ipaddress, socket
def validate_egress_url(cls, v: str) -> str:
parsed = urlparse(v)
if parsed.scheme not in {"http", "https"}:
raise ValueError(f"Disallowed URL scheme: {parsed.scheme}")
hostname = parsed.hostname or ""
try:
ip = ipaddress.ip_address(hostname)
except ValueError:
try:
ip = ipaddress.ip_address(socket.gethostbyname(hostname))
except socket.gaierror:
raise ValueError("Could not resolve egress destination") # fail closed
if ip.is_private or ip.is_loopback or ip.is_link_local or ip.is_reserved or ip.is_multicast:
raise ValueError("Forbidden internal or metadata egress destination")
return vTwo caveats on this fix, not defects in the original so much as things worth being upfront about:
Smaller stuff:
Dispatch-boundary design and the rest of this holds up well. The egress check is the one thing I'd want closed before this merges, everything else here is take-it-or-leave-it. |
…tion Resistance standard
|
Thank @jinsonvarghese @ossumpossum for the sharp review! All applied and pushed:
|
|
Thank you @rashim27us. @ossumpossum will wait for a day or two to see if you have anything to add after a final review. |
|
Final review done. Pulled the current diff and re-ran the same bypass list against the updated validator rather than going off the changelog: Nothing further from me, good to merge as far as I'm concerned. |
Summary
Closes #71
This PR adds advisory requirement
APTS-MR-A04: Final LLM Output Sanitization and Downstream Context Isolation (Advisory)to the standard, addressing the risk of untrusted content reflection and prompt-injection-driven payload emission through LLM outputs (OWASP Top 10 for LLM Applications 2025:LLM05:2025 Improper Output Handling).Following the advisory-first path agreed upon in #71, this practice is introduced as an Advisory Requirement in v0.1.0 to enable immediate adoption, laying the groundwork for promotion to normative
APTS-MR-024(MUST | Tier 2) in v0.2.0.Key Changes & Refinements
New Advisory Requirement (
standard/appendix/Advisory_Requirements.md):argvvectors,shell=False; prohibiting string concatenation tosh -corsystem()).169.254.169.254), and loopback/RFC 1918 addresses.APTS-RP-A01) from payload injection containment (APTS-MR-A04).Implementation Guide (
standard/6_Manipulation_Resistance/Implementation_Guide.md):Manipulation Resistance Domain README (
standard/6_Manipulation_Resistance/README.md):APTS-MR-A04noting its candidate promotion toAPTS-MR-024in v0.2.0.Advisory Count Synchronization (19 → 20):
synchronized the global advisory count across all affected prose documentation files:
README.md(Nineteen → Twenty)index.md(Nineteen → Twenty)standard/README.md(19 → 20)standard/Introduction.md(19 → 20)standard/Frontispiece.md(19 → 20)standard/Getting_Started.md(19 → 20)standard/appendix/Glossary.md(19 → 20)standard/appendix/Vendor_Evaluation_Guide.md(19 → 20)Normative Baseline:
standard/apts_requirements.jsonremains untouched.Verification
Advisory_Requirements.mdparse with correct numbering and headers.APTS-MR-002,APTS-MR-018,APTS-MR-022,APTS-SC-020,APTS-RP-001, andAPTS-RP-A01.