Fix Airflow proxy 500 on JS assets containing '$'/'\' (Airflow 3.2.2)#181
Merged
Merged
Conversation
After bumping apache/airflow to 3.2.2, opening the Airflow perspective
failed with HTTP 500 when loading static JS assets (e.g.
/services/airflow/static/assets/index-*.js):
java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement
at TextResponseBodyRewriter.rewriteFullURLs
The minified JS bundle contains the Airflow URL followed by paths that
include '$' (and '\') characters. Matcher.appendReplacement treats '$'
as a capture-group reference and '\' as an escape, so an unescaped
occurrence in the computed replacement string throws.
Escape the replacement strings with Matcher.quoteReplacement in both
rewriteFullURLs and rewriteEncodedQueryParams, and add a regression test.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
a7c0875 to
f70f049
Compare
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.
Problem
After bumping
apache/airflowfrom 3.0.2 to 3.2.2 (#1f987d7), opening the Airflow perspective fails: the request for static JS assets such as/services/airflow/static/assets/index-C6RXW4nO.jsreturns HTTP 500.The container log shows:
Root cause
TextResponseBodyRewriter.rewriteFullURLsbuilds a replacement string from the matched path and feeds it toMatcher.appendReplacement. That method interprets$as a capture-group reference and\as an escape character. The new Airflow 3.2.2 minified JS bundle contains the Airflow URL immediately followed by paths that include$/\(common in minified JS), so an unescaped$/\in the computed replacement throwsIllegalArgumentException: Illegal group reference, which surfaces as a 500 and breaks the embedded UI.Fix
Escape the replacement strings with
Matcher.quoteReplacement(...)inrewriteFullURLs(the failing path) and, defensively, inrewriteEncodedQueryParams. Added a regression test (rewriteBody_shouldNotFail_whenAirflowUrlIsFollowedByDollarOrBackslash).Testing
mvn test -P unit-tests -Dtest=TextResponseBodyRewriterTest -pl application— 6 tests pass.🤖 Generated with Claude Code