betodealmeida commented on code in PR #35021:
URL: https://github.com/apache/superset/pull/35021#discussion_r2323439901


##########
superset/templates/superset/redirect_warning.html:
##########
@@ -0,0 +1,360 @@
+{#
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements. See the NOTICE file distributed with this 
work
+  for additional information regarding copyright ownership. The ASF licenses 
this
+  file to you under the Apache License, Version 2.0 (the "License"); you may 
not
+  use this file except in compliance with the License. You may obtain a copy of
+  the License at http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software 
distributed
+  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+  CONDITIONS OF ANY KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations under the License.
+#}
+{% extends "superset/spa.html" %}
+
+{% block title %}External Link Warning{% endblock %}
+
+{% block head_css %}
+  {{ super() }}
+  <style nonce="{{ macros.get_nonce() }}">
+    /* Reset body/html backgrounds for proper theming */
+    html, body {
+      margin: 0;
+      padding: 0;
+      height: 100%;
+      background-color: var(--colors-grayscale-light4, #f7f7f7);
+    }
+
+    /* Light mode defaults */
+    .redirect-warning-page {
+      min-height: 100vh;
+      display: flex;
+      align-items: center;
+      justify-content: center;
+      background-color: var(--colors-grayscale-light4, #f7f7f7);
+      padding: var(--gridunit-4, 16px);
+      font-family: var(--font-family-sans-serif, -apple-system, 
BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif);
+    }
+    .warning-container {
+      background: var(--colors-grayscale-light5, #ffffff);
+      border-radius: var(--border-radius-lg, 8px);
+      padding: var(--gridunit-12, 48px);
+      box-shadow: var(--box-shadow-2, 0 4px 12px rgba(0, 0, 0, 0.1));
+      text-align: center;
+      max-width: 600px;
+      width: 100%;
+      font-family: inherit;
+    }
+    .warning-icon {
+      font-size: var(--font-size-xxl, 64px);
+      color: var(--colors-warning-base, #ff6b35);
+      margin-bottom: var(--gridunit-5, 20px);
+    }
+    .warning-title {
+      color: var(--colors-text-label, #2c3e50);
+      font-size: var(--font-size-xl, 24px);
+      font-weight: var(--font-weight-bold, 600);
+      margin-bottom: var(--gridunit-5, 20px);
+      margin-top: 0;
+    }
+    .warning-text {
+      color: var(--colors-text, #666666);
+      font-size: var(--font-size-m, 16px);
+      margin-bottom: var(--gridunit-4, 16px);
+    }
+    .url-display {
+      background-color: var(--colors-grayscale-light3, #f8f9fa);
+      border: 1px solid var(--colors-grayscale-light2, #e9ecef);
+      border-radius: var(--border-radius-sm, 4px);
+      padding: var(--gridunit-3, 12px);
+      margin: var(--gridunit-5, 20px) 0;
+      word-break: break-all;
+      font-family: var(--font-family-monospace, 'Consolas', 'Monaco', 
monospace);
+      font-size: var(--font-size-s, 14px);
+      color: var(--colors-text-label, #333333);
+    }
+    .button-group {
+      margin-top: var(--gridunit-8, 32px);
+      display: flex;
+      gap: var(--gridunit-4, 16px);
+      justify-content: center;
+      flex-wrap: wrap;
+    }
+    .warning-btn {
+      display: inline-flex;
+      align-items: center;
+      justify-content: center;
+      padding: var(--gridunit-3, 12px) var(--gridunit-6, 24px);
+      border-radius: var(--border-radius-sm, 4px);
+      text-decoration: none;
+      font-weight: var(--font-weight-bold, 600);
+      font-size: var(--font-size-m, 16px);
+      cursor: pointer;
+      border: none;
+      transition: all 0.2s ease;
+      min-width: 140px;
+    }
+    .btn-primary {
+      background-color: var(--colors-primary-base, #20a7c9);
+      color: var(--colors-grayscale-light5, #ffffff);
+    }
+    .btn-primary:hover {
+      background-color: var(--colors-primary-dark1, #1a91b8);
+      color: var(--colors-grayscale-light5, #ffffff);
+      text-decoration: none;
+    }
+    .btn-secondary {
+      background-color: var(--colors-grayscale-base, #666666);
+      color: var(--colors-grayscale-light5, #ffffff);
+    }
+    .btn-secondary:hover {
+      background-color: var(--colors-grayscale-dark1, #555555);
+      color: var(--colors-grayscale-light5, #ffffff);
+      text-decoration: none;
+    }
+    .disclaimer {
+      font-size: var(--font-size-s, 14px);
+      color: var(--colors-text, #666666);
+      margin-top: var(--gridunit-6, 24px);
+      line-height: 1.5;
+      padding: var(--gridunit-4, 16px);
+      background-color: var(--colors-info-light2, #f0f9ff);
+      border-left: 3px solid var(--colors-info-base, #1890ff);
+      border-radius: var(--border-radius-sm, 4px);
+      text-align: left;
+    }
+    .trust-section {
+      margin-top: var(--gridunit-6, 24px);
+      margin-bottom: var(--gridunit-2, 8px);
+      display: flex;
+      align-items: center;
+      justify-content: center;
+      gap: var(--gridunit-2, 8px);
+    }
+    .trust-checkbox {
+      width: 18px;
+      height: 18px;
+      cursor: pointer;
+    }
+    .trust-label {
+      font-size: var(--font-size-s, 14px);
+      color: var(--colors-text, #666666);
+      cursor: pointer;
+      user-select: none;
+    }
+
+    /* Dark mode overrides */
+    @media (prefers-color-scheme: dark) {
+      html, body {
+        background-color: var(--colors-grayscale-dark2, #1a1a1a);
+      }
+      .redirect-warning-page {
+        background-color: var(--colors-grayscale-dark2, #1a1a1a);
+      }
+      .warning-container {
+        background: var(--colors-grayscale-dark1, #2e2e2e);
+        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
+      }
+      .warning-title {
+        color: var(--colors-grayscale-light1, #ffffff);
+      }
+      .warning-text {
+        color: var(--colors-grayscale-light2, #b3b3b3);
+      }
+      .url-display {
+        background-color: var(--colors-grayscale-dark3, #1a1a1a);
+        border: 1px solid var(--colors-grayscale-dark1, #404040);
+        color: var(--colors-grayscale-light1, #ffffff);
+      }
+      .disclaimer {
+        background-color: rgba(24, 144, 255, 0.1);
+        border-left-color: var(--colors-info-dark1, #0e5eb8);
+        color: var(--colors-grayscale-light2, #b3b3b3);
+      }
+      .trust-label {
+        color: var(--colors-grayscale-light2, #b3b3b3);
+      }
+      .btn-secondary {
+        background-color: var(--colors-grayscale-dark1, #404040);
+        border: 1px solid var(--colors-grayscale-base, #666666);
+      }
+      .btn-secondary:hover {
+        background-color: var(--colors-grayscale-base, #666666);
+      }
+    }
+
+    /* Explicit dark mode class support (for Superset's theme toggle) */
+    body.dark,
+    html[data-theme="dark"],
+    body[data-theme="dark"] {
+      background-color: var(--colors-grayscale-dark2, #1a1a1a);
+    }
+    body.dark .redirect-warning-page,
+    [data-theme="dark"] .redirect-warning-page {
+      background-color: var(--colors-grayscale-dark2, #1a1a1a);
+    }
+    body.dark .warning-container,
+    [data-theme="dark"] .warning-container {
+      background: var(--colors-grayscale-dark1, #2e2e2e);
+      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
+    }
+    body.dark .warning-title,
+    [data-theme="dark"] .warning-title {
+      color: var(--colors-grayscale-light1, #ffffff);
+    }
+    body.dark .warning-text,
+    [data-theme="dark"] .warning-text {
+      color: var(--colors-grayscale-light2, #b3b3b3);
+    }
+    body.dark .url-display,
+    [data-theme="dark"] .url-display {
+      background-color: var(--colors-grayscale-dark3, #1a1a1a);
+      border: 1px solid var(--colors-grayscale-dark1, #404040);
+      color: var(--colors-grayscale-light1, #ffffff);
+    }
+    body.dark .disclaimer,
+    [data-theme="dark"] .disclaimer {
+      background-color: rgba(24, 144, 255, 0.1);
+      border-left-color: var(--colors-info-dark1, #0e5eb8);
+      color: var(--colors-grayscale-light2, #b3b3b3);
+    }
+    body.dark .trust-label,
+    [data-theme="dark"] .trust-label {
+      color: var(--colors-grayscale-light2, #b3b3b3);
+    }
+    body.dark .btn-secondary,
+    [data-theme="dark"] .btn-secondary {
+      background-color: var(--colors-grayscale-dark1, #404040);
+      border: 1px solid var(--colors-grayscale-base, #666666);
+    }
+    body.dark .btn-secondary:hover,
+    [data-theme="dark"] .btn-secondary:hover {
+      background-color: var(--colors-grayscale-base, #666666);
+    }
+  </style>
+{% endblock %}
+
+{% block body %}
+<div class="redirect-warning-page">
+  <div class="warning-container">
+    <div class="warning-icon">⚠️</div>
+    <h1 class="warning-title">You're leaving Superset</h1>
+    <p class="warning-text">This link is sending you outside of Superset 
to:</p>
+    <div class="url-display">{{ target_url }}</div>
+    <p class="warning-text">Please verify this is a trusted destination before 
continuing.</p>
+
+    <div class="trust-section">
+      <input type="checkbox" id="trustUrl" class="trust-checkbox">
+      <label for="trustUrl" class="trust-label">Trust this exact URL and don't 
ask again</label>
+    </div>
+
+    <div class="button-group">
+      <a href="/" class="warning-btn btn-secondary">Return to Superset</a>
+      <a href="{{ target_url }}" id="continueBtn" class="warning-btn 
btn-primary" target="_blank" rel="noopener noreferrer">
+        Continue to External Site
+      </a>
+    </div>
+
+    <div class="disclaimer">
+      <strong>Security Notice:</strong> Superset cannot guarantee the safety 
of external websites.
+      Only proceed if you trust the destination or its source.
+    </div>
+  </div>
+</div>
+
+<script nonce="{{ macros.get_nonce() }}">
+(function() {
+  const TRUSTED_URLS_KEY = 'superset_trusted_urls';
+  const MAX_TRUSTED_URLS = 100; // Limit to prevent abuse
+
+  // The target URL
+  const targetUrl = '{{ target_url|safe }}';
+
+  // Normalize URL for comparison (remove trailing slashes, fragment)
+  function normalizeUrl(url) {
+    try {
+      const parsed = new URL(url);
+      // Remove fragment and trailing slash from pathname
+      let normalized = parsed.origin + parsed.pathname.replace(/\/$/, '') + 
parsed.search;
+      return normalized;
+    } catch (e) {
+      return url;
+    }
+  }
+
+  // Load trusted URLs from localStorage
+  function getTrustedUrls() {
+    try {
+      const stored = localStorage.getItem(TRUSTED_URLS_KEY);
+      return stored ? JSON.parse(stored) : [];
+    } catch (e) {
+      console.error('Error loading trusted URLs:', e);
+      return [];
+    }
+  }
+
+  // Save trusted URLs to localStorage and cookie
+  function saveTrustedUrls(urls) {
+    try {
+      // Keep only the most recent URLs if we hit the limit
+      if (urls.length > MAX_TRUSTED_URLS) {
+        urls = urls.slice(-MAX_TRUSTED_URLS);
+      }
+      localStorage.setItem(TRUSTED_URLS_KEY, JSON.stringify(urls));

Review Comment:
   There's really no need to encrypt these URLs...



-- 
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: notifications-unsubscr...@superset.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to