Skip to content

fix(widgets): shodan 監査の応答解釈エラーを診断可能にし簡易表示で回避できるようにする - #37

Merged
hitalin merged 1 commit into
mainfrom
fix/shodan-response-diagnostics
Aug 9, 2026
Merged

fix(widgets): shodan 監査の応答解釈エラーを診断可能にし簡易表示で回避できるようにする#37
hitalin merged 1 commit into
mainfrom
fix/shodan-response-diagnostics

Conversation

@hitalin

@hitalin hitalin commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

#36 の追従修正。

なぜ

実運用インスタンス (yami.ski) の監査で ホスト情報を解釈できませんでした に当たった。

エラーの発生条件から状態はここまで絞り込める:

  • HTTP ステータスは正確に 200(404 / 401 / 403 / 429 の分岐を全部通過している)
  • 本文は文字列(Json:parse は非文字列だと例外で落ちるため、穏やかなエラー画面が
    出た時点で文字列だったと確定する)
  • その文字列が JSON として壊れている

/dns/resolve は同じ Vault 接続で成功して IP まで取れているので、認証・接続設定・
API キーは正常。大きい方の /shodan/host の応答だけが壊れている。

Json:parse 自体は 5MB の Shodan 形式 JSON でも問題なく処理できることを実測したので、
AiScript 側の限界ではない。転送層で応答が途中で切れているのが最有力。

ただし旧コードは何が返ってきたのかを一切表示しないため、利用者も作者も
そこから先を切り分けられなかった。そこが本質的な欠陥だった。

何を直したか

1. 応答の診断表示

何が返ってきたのかを出す。本文は外部由来なのでサニタイズしてから表示する。

⚠️ ホスト情報を解釈できませんでした
応答: 38 文字: {"ip_str":"1.2.3.4","data":[{"port":44

切断なのか、HTML が返っているのか、別の何かなのかが一目で分かる。

2. 簡易表示 (minify) での回避

応答が壊れたときだけ「簡易表示で取得 (1 クレジット)」を出す。Shodan の
minify=true は大きいフィールドを切り詰めて返すので、切断が原因なら通る。

バナー詳細が落ちるため稼働サービスと TLS は出ないが、ポートの危険度判定と CVE は残る
結果には「簡易表示」と明記する。

追加で 1 クレジット消費するので自動再取得はしない。 押すかどうかは利用者が選ぶ
(#36 のクレジット方針を維持)。

3. jsonOf の堅牢化

Json:parse は非文字列を渡すと例外で落ちるため型を見てから呼ぶ。
本文が既にパース済みオブジェクトで返る Vault 実装にも対応した。

検証

AiScript 1.2.1 の実インタプリタで 11 系統を回帰(#36 の 9 系統 + 応答切れ +
本文オブジェクト)。全系統で実行時エラー 0 件。

簡易表示ボタン押下後に監査結果へ復帰することと、キャッシュ経路のクレジット消費が
ゼロのままであることも実際にクリックを再現して確認した。

version: 1.0.1 → 1.0.2

残っている不確定要素

真の原因はまだ確定していない。マージ後に実機のエラー画面に出る「応答:」の行を見れば、
切断なのか別要因なのかが判明する。切断で確定すれば恒久対策 (分割取得など) を別途検討する。

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a simplified-output fallback for oversized or malformed Shodan responses.
    • Added retry controls for fetching simplified results, with clear credit-use messaging.
    • Audit results now indicate when simplified output was used.
    • Added notices and labels to clarify simplified results and retry actions.
  • Bug Fixes

    • Improved handling of parsed and malformed response bodies.
    • Added safer error summaries for failed responses.
  • Chores

    • Updated widget metadata and registry timestamps.

yami.ski の監査で「ホスト情報を解釈できませんでした」に当たった。
HTTP 200 かつ本文が文字列でありながら JSON として壊れている状態だが、
旧メッセージは何が返ってきたのかを一切出さないため利用者も作者も
原因を切り分けられなかった。

- 応答の要約 (本文の長さと先頭 60 文字、非文字列ならその型) を表示する。
  本文は外部由来なのでサニタイズしてから出す
- Shodan の minify=true で取り直す導線を追加。応答が大きすぎて途中で
  切れている場合に通ることがある。バナー詳細が落ちるためポートと CVE
  のみになるので、結果に「簡易表示」と明記する。追加で 1 クレジット
  消費するので自動再取得はせず、ボタンで利用者に選ばせる
- jsonOf を堅牢化。Json:parse は非文字列を渡すと例外で落ちるため型を
  見てから呼び、本文が既にパース済みで返る Vault 実装にも対応する

AiScript 1.2.1 の実インタプリタで 11 系統を回帰 (既存 9 + 応答切れ +
本文オブジェクト)。全系統で実行時エラー 0 件、簡易表示ボタン押下後の
復旧とキャッシュ経路のクレジット消費ゼロも確認した。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 9, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
misstore 2643f81 Aug 09 2026, 10:10 AM

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1c17cf92-20e2-402e-8f6f-aa47aa736dea

📥 Commits

Reviewing files that changed from the base of the PR and between 5c953b0 and 2643f81.

📒 Files selected for processing (5)
  • public/registry/index.json
  • public/registry/widgets.json
  • public/registry/widgets/shodan-instance-audit/api.json
  • public/registry/widgets/shodan-instance-audit/meta.json
  • public/registry/widgets/shodan-instance-audit/widget.is

📝 Walkthrough

Walkthrough

The Shodan Instance Audit widget now handles parsed and malformed responses, supports minified host retrieval, records minified results, and offers corresponding UI actions. Registry timestamps and widget release metadata were updated.

Changes

Shodan audit retrieval update

Layer / File(s) Summary
Audit control flow and response handling
public/registry/widgets/shodan-instance-audit/api.json, public/registry/widgets/shodan-instance-audit/widget.is
The widget validates response body types, reports sanitized body previews, supports normal and minify=true audits, records minified results, and exposes retry and display messages.
Widget registry metadata
public/registry/index.json, public/registry/widgets.json, public/registry/widgets/shodan-instance-audit/meta.json
Registry timestamps were updated. The Shodan Instance Audit version changed to 1.0.2, with a new checksum and timestamps.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AuditView
  participant runAudit
  participant ShodanHostEndpoint
  participant jsonOf
  AuditView->>runAudit: request audit
  runAudit->>ShodanHostEndpoint: fetch host details with optional minify=true
  ShodanHostEndpoint-->>runAudit: response body
  runAudit->>jsonOf: parse or validate response body
  jsonOf-->>runAudit: parsed audit data or sanitized diagnostic
  runAudit-->>AuditView: render result or minified retry action
Loading
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/shodan-response-diagnostics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hitalin hitalin self-assigned this Aug 9, 2026
@hitalin
hitalin merged commit 21045ff into main Aug 9, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant