Repository navigation
Release: Page context awareness feature - #20
Merged
Merged
Conversation
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
Member
Author
|
Added CI workflow update for Cloudflare Pages deployment:
Once this PR is merged, the production site should automatically deploy. |
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Merge develop into main for production release.
New Features
fetch_current_pagetool allows assistant to fetch page content when neededSecurity
Testing
Changes
test_page_context.py(agent + API tests)Closes the page context awareness feature implementation.