Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ export function useChannelsColumns(): ColumnDef<Channel>[] {
onClick={(e) => {
e.stopPropagation()
if (!deploymentId) return
const targetUrl = `/console/deployment?deployment_id=${deploymentId}`
const targetUrl = `/models/deployments?dFilter=${encodeURIComponent(String(deploymentId))}`
window.open(targetUrl, '_blank', 'noopener')
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,9 @@ function FailureStatusContent({
variant='outline'
size='sm'
className='h-7 w-fit px-2 text-xs'
onClick={() => window.open('/console/setting?tab=ratio', '_blank')}
onClick={() =>
window.open('/system-settings/billing/model-pricing', '_blank')
}
Comment on lines +762 to +764

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx"

# Show the exact snippet + a little context around the referenced lines
sed -n '740,790p' "$FILE" | nl -ba | sed -n '1,120p'

# Search for other window.open usages in the frontend and summarize patterns
rg -n "window\.open\(" web/default/src --glob='*.ts*' || true

# Specifically find calls that open _blank without noopener/noreferrer (3-arg form or missing third arg)
rg -n --glob='*.ts*' "window\.open\([^)]*['_\"]_blank['\"][^,)]*(?:\)[;}]|\n)" web/default/src || true

Repository: QuantumNous/new-api

Length of output: 106


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx"

echo "== Snippet with line numbers =="
awk 'NR>=740 && NR<=785 {printf "%d\t%s\n", NR, $0}' "$FILE"

echo
echo "== All window.open occurrences (ts/tsx) =="
rg -n "window\.open\(" web/default/src --glob='*.ts*' | head -n 200 || true

echo
echo "== window.open(_blank) missing noopener/noreferrer (best-effort scan) =="
python3 - <<'PY'
import os, re

root = "web/default/src"
target_ext = (".ts", ".tsx")
files=[]
for dirpath, _, filenames in os.walk(root):
    for fn in filenames:
        if fn.endswith(target_ext):
            files.append(os.path.join(dirpath, fn))

# Find window.open occurrences and inspect nearby text for _blank and noopener/noreferrer.
# Best-effort: examines up to N chars after the call site.
N=600

occ_re = re.compile(r'window\s*\.?\s*open\s*\(')

def linecol(text, idx):
    # compute 1-based line and column
    line = text.count('\n', 0, idx) + 1
    last_nl = text.rfind('\n', 0, idx)
    col = idx - last_nl if last_nl != -1 else idx + 1
    return line, col

bad=[]
for path in files:
    try:
        with open(path, "r", encoding="utf-8") as f:
            s=f.read()
    except Exception:
        continue
    for m in occ_re.finditer(s):
        i=m.start()
        chunk = s[i:i+N]
        if ("'_blank'" in chunk) or ('"_blank"' in chunk) or ("_blank" in chunk):
            # consider it "has protections" if both substrings appear somewhere nearby
            # (covers typical "'noopener,noreferrer'" or separate 'noopener'/'noreferrer')
            has_noop = "noopener" in chunk
            has_noref = "noreferrer" in chunk
            if not (has_noop and has_noref):
                # find line number
                line, col = linecol(s, i)
                snippet = chunk.splitlines()[0][:180]
                bad.append((path, line, col, snippet))
                break  # report at most once per file to keep output bounded

print("Matches:")
if not bad:
    print("None found (best-effort).")
else:
    for path,line,col,snippet in bad[:200]:
        print(f"- {path}:{line}:{col} :: {snippet}")
PY

Repository: QuantumNous/new-api

Length of output: 6792


Harden window.open(..., '_blank') against tabnabbing/referrer leakage

  • web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx uses window.open(..., '_blank') without noopener,noreferrer (lines 762-764); add the third argument to prevent opener/referrer leakage.
  • Other _blank callsites also lack full protection and should be updated similarly:
    web/default/src/components/layout/components/chat-presets-item.tsx, web/default/src/features/channels/components/channels-columns.tsx, web/default/src/features/keys/components/dialogs/cc-switch-dialog.tsx, web/default/src/features/keys/components/data-table-row-actions.tsx, web/default/src/features/models/components/dialogs/view-details-dialog.tsx, web/default/src/features/playground/components/message-error.tsx, web/default/src/features/subscriptions/components/dialogs/subscription-purchase-dialog.tsx, web/default/src/features/system-settings/integrations/ionet-deployment-settings-section.tsx, web/default/src/features/usage-logs/components/dialogs/audio-preview-dialog.tsx, web/default/src/features/wallet/hooks/use-creem-payment.ts, web/default/src/features/wallet/hooks/use-payment.ts, web/default/src/features/wallet/hooks/use-waffo-payment.ts, web/default/src/lib/oauth.ts.
Suggested fix
-            onClick={() =>
-              window.open('/system-settings/billing/model-pricing', '_blank')
-            }
+            onClick={() =>
+              window.open(
+                '/system-settings/billing/model-pricing',
+                '_blank',
+                'noopener,noreferrer'
+              )
+            }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onClick={() =>
window.open('/system-settings/billing/model-pricing', '_blank')
}
onClick={() =>
window.open(
'/system-settings/billing/model-pricing',
'_blank',
'noopener,noreferrer'
)
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/default/src/features/channels/components/dialogs/channel-test-dialog.tsx`
around lines 762 - 764, Multiple call sites open external pages with
window.open(..., '_blank') (e.g., the window.open in channel-test-dialog.tsx) or
anchor elements without rel protection; update each to prevent
tabnabbing/referrer leakage by adding the third window.open argument
"noopener,noreferrer" (e.g., window.open(url, '_blank', 'noopener,noreferrer'))
and, where an <a> element is used (e.g., in ChatPresetsItem, ChannelsColumns,
ViewDetailsDialog, MessageError, SubscriptionPurchaseDialog,
IonetDeploymentSettingsSection, AudioPreviewDialog and similar), add
rel="noopener noreferrer" alongside target="_blank"; also update the hook files
(use-creem-payment, use-payment, use-waffo-payment) and oauth.ts to use the same
window.open signature so all listed symbols are hardened.

>
<Settings className='mr-1 h-3 w-3 shrink-0' />
{t('Go to Settings')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function MessageError({ message, className = '' }: MessageErrorProps) {
variant='outline'
size='sm'
onClick={() =>
window.open('/console/setting?tab=ratio', '_blank')
window.open('/system-settings/billing/model-pricing', '_blank')
}
Comment on lines 59 to 61

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use secure window.open features for the new-tab link.

Please include noopener,noreferrer for this _blank navigation to avoid opener/referrer exposure.

Suggested fix
-              onClick={() =>
-                window.open('/system-settings/billing/model-pricing', '_blank')
-              }
+              onClick={() =>
+                window.open(
+                  '/system-settings/billing/model-pricing',
+                  '_blank',
+                  'noopener,noreferrer'
+                )
+              }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onClick={() =>
window.open('/console/setting?tab=ratio', '_blank')
window.open('/system-settings/billing/model-pricing', '_blank')
}
onClick={() =>
window.open(
'/system-settings/billing/model-pricing',
'_blank',
'noopener,noreferrer'
)
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/default/src/features/playground/components/message-error.tsx` around
lines 59 - 61, The onClick handler that opens
'/system-settings/billing/model-pricing' in a new tab should pass secure
window.open features to prevent opener/referrer leakage; update the onClick in
the MessageError component (the onClick that calls
window.open('/system-settings/billing/model-pricing', '_blank')) to include the
third argument "noopener,noreferrer" (or convert to an anchor element with
target="_blank" and rel="noopener noreferrer") so the new-tab navigation uses
noopener and noreferrer.

>
<Settings className='mr-1 h-3.5 w-3.5' />
Expand Down