fix: resolve KnowledgeGraphNode hash collision due to template rendering bugs#709
Open
3em0 wants to merge 1 commit intopingcap:mainfrom
Open
fix: resolve KnowledgeGraphNode hash collision due to template rendering bugs#7093em0 wants to merge 1 commit intopingcap:mainfrom
3em0 wants to merge 1 commit intopingcap:mainfrom
Conversation
…ing bugs
Two bugs in KnowledgeGraphNode caused hash/get_content to ignore actual
entity and relationship data, producing identical outputs for completely
different knowledge graph nodes.
Bug 1: Templates used Jinja2 double-brace syntax ({{ name }}) but were
rendered with Python str.format(), which treats {{ as literal {. All
format kwargs were silently ignored.
Bug 2: _get_relationships_str() used self.entity_template instead of
self.relationship_template, so relationship data never reached the output.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Someone is attempting to deploy a commit to the pingcap Team on Vercel. A member of the Team first needs to authorize it. |
Author
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.
VUL-01 — KnowledgeGraphNode Hash Collision (Severity: High)
Category: Content collision / Hash invalidation
Affected:
backend/app/rag/retrievers/knowledge_graph/schema.py—KnowledgeGraphNode.hash,get_content(),_get_entities_str(),_get_relationships_str()Root Cause
Two independent bugs combine to make
KnowledgeGraphNode.hashandget_content()completely ignore actual entity and relationship data:Bug 1 — Template syntax mismatch (L199-208):
Templates used Jinja2 double-brace syntax (
{{ name }}) but were rendered with Pythonstr.format(), which treats{{as a literal{escape. All format keyword arguments were silently ignored — every entity and relationship rendered to the same constant string regardless of content.Bug 2 — Wrong template reference (L286):
_get_relationships_str()usedself.entity_templateinstead ofself.relationship_template. Relationship fields (rag_description,weight,last_modified_at,meta) were passed as kwargs to the entity template which has no matching placeholders — all silently discarded.Attack Chain
Impact
hashis effectively:f(query_text, len(entities), len(relationships))— actual content never enters the computationget_content()returns constant placeholder text instead of real entity/relationship data, affecting any downstream consumer (rerankers, tracing, logging)CVSS estimate: 7.5 (High) — No authentication required, impacts data integrity and availability.
Fix
DEFAULT_ENTITY_TMPL(L199-202){{ name }}→{name},{{ description }}→{description}DEFAULT_RELATIONSHIP_TMPL(L203-208){{ rag_description }}→{rag_description}, etc._get_relationships_str()(L286)self.entity_template.format(→self.relationship_template.format(Verification
Tested with two
KnowledgeGraphNodeinstances sharing the same query and entity/relationship counts but completely different content:5bfcc6e84d7dc0f987e19626d09c3fbf...(collision)c5838f01...vsfd7e8c14...(no collision, content correctly differentiated)🤖 Generated with Claude Code