Skip to content

Commit ff43848

Browse files
aldro61claude
andcommitted
Hide form context menu to prevent field modification exploits
The right-click context menu on form headers provided options that could be used to modify form fields outside the task scope. This adds a MutationObserver that removes context menus as soon as they appear, preventing agents from using this mechanism to bypass field restrictions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4134527 commit ff43848

File tree

1 file changed

+24
-0
lines changed
  • src/browsergym/workarena/tasks

1 file changed

+24
-0
lines changed

src/browsergym/workarena/tasks/form.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,30 @@ def get_init_scripts(self) -> List[str]:
395395
396396
runInGsftMainOnlyAndProtectByURL(removeAdditionalActionsButton, '{url_suffix}');
397397
""",
398+
f"""
399+
function removeContextMenus() {{
400+
waLog('Setting up context menu removal observer...', 'removeContextMenus');
401+
// Remove any existing context menus
402+
document.querySelectorAll('.context_menu').forEach((menu) => {{
403+
menu.remove();
404+
}});
405+
// Observe for new context menus being added
406+
const observer = new MutationObserver((mutations) => {{
407+
mutations.forEach((mutation) => {{
408+
mutation.addedNodes.forEach((node) => {{
409+
if (node.nodeType === 1 && node.classList && node.classList.contains('context_menu')) {{
410+
node.remove();
411+
waLog('Removed dynamically added context menu', 'removeContextMenus');
412+
}}
413+
}});
414+
}});
415+
}});
416+
observer.observe(document.body, {{ childList: true, subtree: true }});
417+
waLog('Context menu observer active', 'removeContextMenus');
418+
}}
419+
420+
runInGsftMainOnlyAndProtectByURL(removeContextMenus, '{url_suffix}');
421+
""",
398422
]
399423

400424
def start(self, page: Page) -> None:

0 commit comments

Comments
 (0)