pierrejeambrun commented on code in PR #63141:
URL: https://github.com/apache/airflow/pull/63141#discussion_r2912672699


##########
airflow-core/newsfragments/63141.bugfix.rst:
##########
@@ -0,0 +1 @@
+Fix security iframe navigation when AIRFLOW__API__BASE_URL basename is 
configured

Review Comment:
   We do not use newsframgnets for bugfixes. Only for 'significant' ones. 
   
   Can you remove this file please.



##########
airflow-core/src/airflow/ui/src/pages/Security.tsx:
##########
@@ -43,8 +43,18 @@ export const Security = () => {
   const onLoad = () => {
     const iframe: HTMLIFrameElement | null = 
document.querySelector("#security-iframe");
 
-    if (iframe?.contentWindow && 
!iframe.contentWindow.location.pathname.startsWith("/auth/")) {
-      void Promise.resolve(navigate("/"));
+    if (iframe?.contentWindow) {
+      const baseHref = document.querySelector("base")?.href;
+      const basename = baseHref === undefined ? "" : new 
URL(baseHref).pathname.replace(/\/$/u, "");
+
+      const iframePath = iframe.contentWindow.location.pathname;
+      const pathWithoutBase = iframePath.startsWith(basename)
+        ? iframePath.slice(basename.length)
+        : iframePath;
+
+      if (!pathWithoutBase.startsWith("/auth/")) {
+        void Promise.resolve(navigate("/"));
+      }
     }

Review Comment:
   This is overly complicated I believe:
   ```suggestion
       if (iframe?.contentWindow) {
         const base = new URL(document.baseURI).pathname.replace(/\/$/u, ""); 
// Remove trailing slash if exists
   
         if 
(!iframe.contentWindow.location.pathname.startsWith(`${base}/auth/`)) {
           void Promise.resolve(navigate("/"));
         }
       }
     };
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to