fix: harden oauth popup messaging - #182
Conversation
f8bf4c1 to
dc8a3b1
Compare
|
Thanks for the hardening here as well @Rohithmatham12 🚀. One issue still remains in the popup HTML generation. The payload is now serialized with JSON, which fixes JavaScript string escaping, but it is still embedded directly inside an inline <script>. If the message contains </script>, the browser HTML parser can close the script tag before JavaScript parsing happens. For example, an error message like </script><script>window.__xss = true</script> is emitted raw in the callback HTML. Could you also escape the JSON for safe inline script embedding, for example by replacing < with \u003c after json.dumps, and add a regression test that verifies </script> is not present in the generated HTML payload? This may have existed before this PR, but since the PR is hardening this exact popup messaging path, it would be good to close it here. 🤗 |
dc8a3b1 to
61068a0
Compare
|
Thanks for catching that. I updated both OAuth popup helpers to escape the JSON after serialization before embedding it in the inline script, covering Reran lint, typecheck, build, ruff format/check, diff check, and the targeted OAuth test module. |
|
Thx @Rohithmatham12 🚀 |
Summary
postMessagecalls to the callback page origin instead of using a wildcard target</script>payloads in regression testsTesting
bun run lint:checkbun run typecheckbun run builduv run ruff format --check .uv run ruff check .git diff --checkSECRET_KEY=test-secret-key-for-tests-only-32-bytes ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000001 uv run python -m unittest tests.test_google_sheets_oauth(19 passed)SECRET_KEY=test-secret-key-for-tests-only-32-bytes ENCRYPTION_KEY=0000000000000000000000000000000000000000000000000000000000000001 ./run_tests.sh(986 passed before the follow-up inline-script escape)