Skip to content

fix: avoid script dedup key collisions#39

Open
saschabuehrle wants to merge 1 commit intoCopilotKit:mainfrom
saschabuehrle:fix/issue-37-script-dedup-key
Open

fix: avoid script dedup key collisions#39
saschabuehrle wants to merge 1 commit intoCopilotKit:mainfrom
saschabuehrle:fix/issue-37-script-dedup-key

Conversation

@saschabuehrle
Copy link
Copy Markdown

Fixes #37

The script dedup key was truncated to 16 chars, which can collide for scripts with similar prefixes. This uses the full base64 key so different scripts no longer share the same exec marker.

Greetings, saschabuehrle

Copy link
Copy Markdown

@JiwaniZakir JiwaniZakir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix correctly addresses the dedup key collision by removing .slice(0, 16) in widget-renderer.tsx, but it introduces a different concern: btoa(key) can produce characters like +, /, and = that are technically invalid in HTML attribute names. While most browsers handle getAttribute/setAttribute leniently with these characters, relying on that behavior is fragile. Consider using a URL-safe base64 variant (replacing + with -, / with _, and stripping =) or a simple hash function instead.

Additionally, when scriptInfo.text contains a large inline script, the full base64 of that content becomes the attribute name — potentially a very long string. A short, collision-resistant hash (e.g., a 32-bit FNV or even a truncated SHA-256 via crypto.subtle) would be both safer and more efficient here. The original .slice(0, 16) was trying to keep attribute names manageable; the right fix is to use a proper hash rather than truncated base64.

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.

Script dedup key truncation may cause collisions

2 participants