Skip to content

Load the AWS WAF SDK from the page head - #4841

Merged
reakaleek merged 5 commits into
mainfrom
fix/waf-sdk-late-integration
Nov 12, 2026
Merged

reakaleek merged 5 commits into
mainfrom
fix/waf-sdk-late-integration

Conversation

@reakaleek

@reakaleek reakaleek commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Why

  • On edge, the telemetry token wait from Telemetry: wait for the AWS WAF token before each export #4817 gives up right away, so exports don't wait for the AWS WAF token.
  • The JS loader in waf.ts added the SDK script and checked for window.AwsWafIntegration on its load event. jsapi.js is a loader for challenge.js, and the global only exists after challenge.js runs, so the check failed. Page feedback had the same failure on first load, hidden by its retry on submit.
  • Telemetry now loads the SDK on every page where waf_integration_url is set, so a JS loader adds nothing. AWS documents a plain script tag in <head>.

Part of elastic/docs-eng-team#1192

What

  • _Head.cshtml renders <script src="{waf_integration_url}" async> when the effective frontend config has the URL: assembler builds, not air-gapped. The token fetch starts while the HTML parses, and a slow WAF endpoint can't delay DOMContentLoaded.
  • waf.ts no longer injects scripts. waitForWafSdk waits up to 5 seconds for AwsWafIntegration. Page feedback and telemetry use it, and the page feedback warm-up effect is gone.
  • docs/development/page-feedback.md describes the head tag and why the URL is the CAPTCHA jsapi.js.

Notes

  • Keep jsapi.js, the documented route for our web ACLs. The console's Intelligent threat integration tab, which gives a per-web-ACL challenge.js, only lists web ACLs with the ACFP or ATP rule groups or targeted Bot Control. Ours use common Bot Control. The account-level challenge.js also works, but AWS doesn't document that URL (Load the AWS WAF challenge.js directly on edge and demo #4842, closed).

  • Seen on edge in a clean browser context with the old loader:

    Time Event
    137 ms jsapi.js appended
    408 ms jsapi.js load, global missing (old loader fails here)
    592 ms AwsWafIntegration set
    714 ms mp_verify done
    1144 ms first /o/l export, cookie present by luck
  • htmx keeps the identical head tag across navigations, as with elastic-nav.js, so the SDK isn't loaded again.

🤖 Generated with Claude Code

@reakaleek
reakaleek requested a review from a team as a code owner November 12, 2026 15:47
@reakaleek reakaleek added the bug label Nov 12, 2026
@reakaleek
reakaleek requested a review from technige November 12, 2026 15:47
@reakaleek

Copy link
Copy Markdown
Member Author

Replaced by #4842. Loading challenge.js directly fixes the same failure with no code change, one fewer request, and an earlier token.

@reakaleek reakaleek closed this Nov 12, 2026
@reakaleek
reakaleek deleted the fix/waf-sdk-late-integration branch November 12, 2026 15:50
@reakaleek reakaleek reopened this Nov 12, 2026
@reakaleek reakaleek changed the title Wait for AwsWafIntegration after the WAF SDK script loads Load the AWS WAF SDK from the page head Nov 12, 2026
reakaleek and others added 2 commits November 12, 2026 17:07
…r review by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eview by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

@reakaleek
reakaleek merged commit c70a328 into main Nov 12, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant