Skip to content

feat(memory): a guarded fetch, and UrlLoader over any loader source - #249

Merged
jddunn merged 6 commits into
masterfrom
feat/guarded-url-fetch
Oct 10, 2026
Merged

jddunn merged 6 commits into
masterfrom
feat/guarded-url-fetch

Conversation

@jddunn

@jddunn jddunn commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds guardedFetch for addresses a person gives a server, and lets UrlLoader take any { getLoader } with an injected fetchDocument.

Linked issues

Closes #240

Type of change

  • Bug fix
  • Feature
  • Performance
  • Documentation
  • Refactor
  • Tests
  • Build or CI

How this was verified

src/cognition/memory/io/ingestion/__tests__/guardedFetch.test.ts (8 cases, against a loopback server reached through a made-up host and a stand-in resolver) and __tests__/UrlLoader.test.ts (5), in CI. The tests were pushed first, on their own, and read red at the type check on the missing module and options (run 38069596625); with the code, Test & Lint, Batch-1 gated tests and Release dry run are green (run 38070142912), and again with two more cases for a protocol upgrade, a coding the request did not ask for, the caller's abort and options out of range (run 38070635221).

A review follow-up adds the fifth UrlLoader case: with fetchDocument, an HTML, XHTML or PDF answer the loader source has no loader for is refused with an error that names the media type and not the address, where the first version returned the raw markup as the text. That case was pushed first and read red on its assertion (run 38077613895), and is green with the fix (run 38077947877). The third guardedFetch case now also reads the Host header the stand-in received: it names the host, though the connection went to the checked address.

Migration notes

None.

Checklist

  • Tests cover the changed behavior.
  • Docs are updated.
  • The title follows Conventional Commits, with ! before the colon for a change that breaks users (feat!: or feat(api)!:).
  • No secrets or private data are included.
  • Every automated review thread is settled (how).
  • I have read this change and can explain every line.

Summary by Sourcery

Add secure fetching for user-supplied addresses and make UrlLoader configurable with injected fetching and arbitrary loader sources.

New Features:

  • Add guarded fetching for user-supplied HTTP(S) addresses with DNS rebinding protection, public-address checks, redirect controls, response limits, content validation, decompression, deadlines, and typed failure reasons.

Enhancements:

  • Allow UrlLoader to use any loader source and an injected document fetcher while preserving compatibility with LoaderRegistry and global fetch.
  • Expose the new guarded-fetch and UrlLoader APIs through the memory package.
  • Document secure user-supplied address ingestion and loader behavior.

Documentation:

  • Expand memory ingestion documentation with guardedFetch usage, security rules, and API references.

Tests:

  • Add coverage for guardedFetch address validation, redirects, limits, content handling, aborts, deadlines, and option validation.
  • Add coverage for UrlLoader injected fetching, HTML/XHTML/PDF routing, missing-loader errors, and backward compatibility.

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 6 billable files and costs up to $1.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 1 minute for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: framerslab/agentos/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 6bacb479-dea7-4863-b2f4-d98702bf7e3a

📥 Commits

Reviewing files that changed from the base of the PR and between e0da545 and ac1c2b7.


📒 Files selected for processing (6)
  • docs/memory/MEMORY_DOCUMENT_INGESTION.md
  • src/cognition/memory/index.ts
  • src/cognition/memory/io/ingestion/UrlLoader.ts
  • src/cognition/memory/io/ingestion/__tests__/UrlLoader.test.ts
  • src/cognition/memory/io/ingestion/__tests__/guardedFetch.test.ts
  • src/cognition/memory/io/ingestion/guardedFetch.ts

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduces a security-hardened fetch pipeline for externally supplied URLs and refactors UrlLoader to consume arbitrary loader sources with injectable fetching, while maintaining existing LoaderRegistry/global-fetch compatibility.

File-Level Changes

Change Details Files
Add SSRF-resistant guarded document fetching for user-supplied URLs.
  • Validate URL schemes, credentials, ports, DNS results, and public address requirements before connecting.
  • Pin each request to the address that was validated, including redirect hops, with a redirect limit.
  • Enforce response type, decompressed byte limits, and read deadlines; return structured guard failure reasons.
  • Expose public-address classification and fetch response metadata/body for downstream loaders.
src/cognition/memory/io/ingestion/guardedFetch.ts
src/cognition/memory/io/ingestion/__tests__/guardedFetch.test.ts
Generalize UrlLoader to work with arbitrary loader sources and injectable document fetching while preserving existing behavior.
  • Accept any LoaderSource implementing getLoader rather than requiring a LoaderRegistry.
  • Add fetchDocument injection and retain global fetch as the default path.
  • Select loaders from the final fetched URL and normalized content type, including XHTML through the HTML loader and PDF through the PDF loader.
  • Preserve URL capability checks and compatibility with existing LoaderRegistry callers.
src/cognition/memory/io/ingestion/UrlLoader.ts
src/cognition/memory/io/ingestion/__tests__/UrlLoader.test.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#240 Implement guardedFetch that resolves each host before connecting and rejects private, loopback, link-local, unique-local, multicast, reserved, unspecified, and IPv4-mapped or translated IPv6 addresses; validates every redirect and checked connection; limits redirects, schemes, and ports; enforces streaming size and deadline limits; and restricts accepted content types. ❌ The PR diff only adds tests for guardedFetch. It does not include the guardedFetch implementation or any production code changes that enforce these protections.
#240 Update UrlLoader to accept any loader source exposing getLoader(extension), support an injected optional fetchDocument, and retain compatibility with existing LoaderRegistry and global-fetch callers. ❌ The PR diff only adds UrlLoader tests. No UrlLoader production changes are shown to accept arbitrary loader sources or an injected fetchDocument, nor to preserve the existing behavior.
#240 Allow servers to provide guardedFetch and their own loaders without constructing a LoaderRegistry. ❌ Although the tests describe and exercise the intended API, the diff contains no implementation changes enabling servers to inject guardedFetch and custom loaders.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

…d not ask for, the caller's abort and options out of range
@jddunn
jddunn marked this pull request as ready for review October 10, 2026 17:16
@jddunn
jddunn requested a review from Victor-Evogor as a code owner October 10, 2026 17:16
@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Sorry @jddunn, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 11 hours and 29 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add guarded URL fetching and injectable document loading

✨ Enhancement 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Add guarded HTTP(S) fetching to limit server access to unsafe addresses and responses.
• Let UrlLoader use any loader source and an injected fetcher while preserving its default behavior.
• Test security boundaries and document the new ingestion API.
Diagram

sequenceDiagram
    actor C as Caller
    participant U as UrlLoader
    participant G as guardedFetch
    participant D as DNS resolver
    participant W as Remote server
    participant L as Loader source
    C->>U: load address
    U->>G: injected fetchDocument
    loop Each URL hop
        G->>D: resolve host
        D-->>G: all addresses
        Note over G: Reject unsafe addresses; pin selected IP
        G->>W: GET checked IP
        W-->>G: response or redirect
    end
    Note over G: Enforce type, size, and deadline
    G-->>U: final URL, type, body
    U->>L: getLoader by type
    L-->>U: HTML or PDF loader
    U-->>C: document with final source
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Share transport with existing untrusted-image fetching
  • ➕ One implementation to audit for address validation, redirects, and bounded reads.
  • ➕ Reduces duplication of security-sensitive transport logic.
  • ➖ Requires a broader refactor of an established image-fetch path.
  • ➖ Image and document fetching have different response policies and public APIs.

Recommendation: Keep the document-specific fetcher and injected UrlLoader boundary for this PR: they add guarded document ingestion without changing image fetching or existing UrlLoader callers. Consider extracting a shared transport later if both implementations continue to evolve; review their security behavior for divergence.

Files changed (6) +944 / -9

Enhancement (3) +518 / -8
index.tsExport guarded fetching and loader extension types +3/-0

Export guarded fetching and loader extension types

• Exposes guardedFetch, its error and address-check helper, associated types, and the UrlLoader injection interfaces through the memory API.

src/cognition/memory/index.ts

UrlLoader.tsAccept interchangeable loader sources and document fetchers +116/-8

Accept interchangeable loader sources and document fetchers

• Broadens loader lookup to any object with getLoader and optionally consumes an injected document fetcher. The injected path routes HTML, XHTML, and PDF to format loaders and uses the final fetched URL as source metadata; the existing global-fetch path remains.

src/cognition/memory/io/ingestion/UrlLoader.ts

guardedFetch.tsImplement bounded fetching of user-supplied URLs +399/-0

Implement bounded fetching of user-supplied URLs

• Adds HTTP(S) fetching that checks every resolved address and redirect destination, then connects to a checked address without a second lookup. Enforces allowed ports and media types, response status, decoded-body size, a whole-request deadline, and cancellation with categorized errors.

src/cognition/memory/io/ingestion/guardedFetch.ts

Tests (2) +390 / -0
UrlLoader.test.tsTest injected fetch routing and legacy loading +131/-0

Test injected fetch routing and legacy loading

• Covers HTML, XHTML, and PDF delegation through a lightweight loader source, including final-URL metadata. Verifies LoaderRegistry and global fetch still work without injection.

src/cognition/memory/io/ingestion/tests/UrlLoader.test.ts

guardedFetch.test.tsExercise guarded fetching against a local server +259/-0

Exercise guarded fetching against a local server

• Tests address rejection and pinned resolution, redirect checks, decoded size limits, deadlines, media types, protocol upgrades, unsupported encodings, caller aborts, and invalid options. Uses a loopback server and stand-in resolver to avoid external network access.

src/cognition/memory/io/ingestion/tests/guardedFetch.test.ts

Documentation (1) +36 / -1
MEMORY_DOCUMENT_INGESTION.mdDocument guarded URL ingestion +36/-1

Document guarded URL ingestion

• Explains the risks of user-supplied addresses, guardedFetch limits and errors, and how to inject it into UrlLoader with a lightweight loader source. Adds the new module to the ingestion reference.

docs/memory/MEMORY_DOCUMENT_INGESTION.md

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (1) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Fetches reach the wrong default port 📎 Requirement gap ⛨ Security
Description
checkedUrl accepts either 80 or 443 without checking which scheme the URL uses. With default
options, http: can reach port 443 and https: can reach port 80, and each accepted URL proceeds
to address validation and a connection attempt.
Code

src/cognition/memory/io/ingestion/guardedFetch.ts[R166-167]

+  const port = url.port === '' ? (url.protocol === 'https:' ? 443 : 80) : Number(url.port);
+  if (!ports.includes(port)) throw new GuardedFetchError('port', `port ${port} is not read`);
Evidence
Rule 4 requires each scheme to use its respective default port. The default list contains both
ports, while checkedUrl tests only whether the selected port appears in that list.

Restrict schemes and ports
src/cognition/memory/io/ingestion/guardedFetch.ts[109-110]
src/cognition/memory/io/ingestion/guardedFetch.ts[164-169]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The default port check accepts both default ports for either URL scheme.
## Fix Focus Areas
- src/cognition/memory/io/ingestion/guardedFetch.ts[157-169]
- src/cognition/memory/io/ingestion/__tests__/guardedFetch.test.ts[205-230]
## Recommended Fix
When using default port policy, require port 80 for HTTP and port 443 for HTTPS. Add tests that reject HTTP on 443 and HTTPS on 80.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Reachable sites fail on a bad first address 🐞 Bug ☼ Reliability
Description
checkedAddress returns only the first validated DNS answer, and requestOnce pins the connection
to it without trying another answer. When a host's first address is unreachable but a later address
is reachable, guardedFetch fails with a network error instead of reading the site.
Code

src/cognition/memory/io/ingestion/guardedFetch.ts[R210-211]

+  const first = answers[0];
+  return { address: first.address, family: isIP(first.address) === 6 ? 6 : 4 };
Evidence
The default resolver requests all addresses in verbatim order, but checkedAddress discards all
except the first. The request's lookup callback then supplies only that selected address, so the
remaining validated answers cannot be used if its connection fails.

src/cognition/memory/io/ingestion/guardedFetch.ts[360-361]
src/cognition/memory/io/ingestion/guardedFetch.ts[203-211]
src/cognition/memory/io/ingestion/guardedFetch.ts[232-245]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A DNS name may have multiple validated addresses, but guardedFetch connects only to the first. An unreachable first address makes the fetch fail even when another answer is reachable.
## Fix Focus Areas
- src/cognition/memory/io/ingestion/guardedFetch.ts[195-212]
- src/cognition/memory/io/ingestion/guardedFetch.ts[232-245]
- src/cognition/memory/io/ingestion/guardedFetch.ts[372-375]
## Recommended Fix
Validate every DNS answer before making any connection, then attempt the validated addresses in order within the existing deadline. Keep each attempt pinned to its checked address, and proceed to the next address only after a connection failure.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@jddunn
jddunn merged commit a531e02 into master Oct 10, 2026
9 checks passed
@jddunn
jddunn deleted the feat/guarded-url-fetch branch October 10, 2026 19:11
github-actions Bot pushed a commit that referenced this pull request Oct 10, 2026
## [0.13.35](v0.13.34...v0.13.35) (2026-10-10)

### feat

* **memory:** a guarded fetch, and UrlLoader over any loader source (#249) ([a531e02](a531e02))

### ci

* **links:** the online link check takes github.com's 429 and 503 as reachable (#259) ([90ca3c7](90ca3c7))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A guarded fetch for addresses a person gives a server, and UrlLoader over any loader source

1 participant