Skip to content

Release: Page context awareness feature - #20

Merged
neuromechanist merged 6 commits into
mainfrom
develop
Jan 9, 2026
Merged

neuromechanist merged 6 commits into
mainfrom
develop

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

Merge develop into main for production release.

New Features

  • Page context awareness: Chat assistant can now see the current page URL and title to provide more contextually relevant answers
  • Widget shows "Page context enabled" notice when feature is active
  • fetch_current_page tool allows assistant to fetch page content when needed

Security

  • Comprehensive SSRF protection for URL fetching
  • DNS rebinding attack prevention
  • Private IP range blocking
  • Content-type validation
  • Redirect chain protection

Testing

  • 87% test coverage for hed.py
  • 54 new tests for page context feature
  • Manual testing completed successfully

Changes

  • 8 files changed, 964 insertions
  • New test files: test_page_context.py (agent + API tests)
  • Added localhost:8888 to default CORS origins

Closes the page context awareness feature implementation.

claude and others added 6 commits January 9, 2026 04:08
This feature allows the chat assistant to be aware of the page where
the widget is embedded, enabling more contextually relevant answers.

Changes:
- Frontend: Capture page URL and title, send with API requests via
  page_context field. New includePageContext config option (default: true)
- API: Add PageContext model and page_context field to AskRequest,
  pass through to HEDAssistant
- Agent: Add PageContext dataclass, include in system prompt when
  provided, add fetch_page_content tool to retrieve page content
  when the user's question relates to the embedded page
- Dependencies: Add markdownify for HTML-to-markdown conversion
Security improvements:
- Add SSRF protection with IP/domain validation (blocks private IPs,
  localhost, link-local, and reserved ranges)
- Validate redirect targets to prevent redirect-based SSRF
- Disable automatic redirects and handle them manually with validation
- Add URL scheme validation at API layer (max length, valid scheme)
- Add title max length validation to prevent DoS
- Validate content-type to ensure HTML responses only

Tool design improvements:
- Create bound fetch_current_page tool that only fetches the specific
  page URL from page_context (prevents LLM from requesting arbitrary URLs)
- Move imports to module level for better performance

Privacy improvements:
- Add privacy notice in frontend widget when page context is enabled
- Add configurable showPageContextNotice and pageContextNoticeText options

Tests:
- Add comprehensive tests for SSRF protection (37 new tests)
- Test localhost, private IPs, link-local, reserved IPs are blocked
- Test valid public URLs are allowed
- Test PageContext model validation
- Test HEDAssistant with and without page context
- Fix silent DNS failure handling: return error instead of passing
- Add specific exception handling for socket errors (gaierror, herror, timeout)
- Add comprehensive logging for all security events
- Make URL validation explicit: raise ValueError for invalid schemes
- Return resolved IP from is_safe_url to mitigate TOCTOU attacks
- Add comprehensive tests for redirect SSRF, content-type validation,
  timeout handling, and tool invocation
- Achieve 87% coverage for page context code in hed.py
…t-awareness-oSA5R

feat: add page context awareness to chat assistant
- main branch deploys to osa-demo.pages.dev (production)
- develop branch deploys to develop.osa-demo.pages.dev (preview)
- Added workflow file to paths trigger
@neuromechanist

Copy link
Copy Markdown
Member Author

Added CI workflow update for Cloudflare Pages deployment:

  • main branch → deploys to osa-demo.pages.dev (production)
  • develop branch → deploys to develop.osa-demo.pages.dev (preview)

Once this PR is merged, the production site should automatically deploy.

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.

2 participants