Repository navigation
feat(brand-builder): smart paste import for brand.json properties - #3396
Merged
Merged
Conversation
bokelley
force-pushed
the
claude/issue-2180-smart-paste-property-import
branch
from
April 30, 2026 01:20
b542434 to
36aa008
Compare
Closes #2180 Add AI-powered property list import to the brand builder. Network operators managing large publisher inventories can now paste a domain list (spreadsheet column, email, free-form text) or supply a public CSV / Google Sheets URL and have Claude extract structured { identifier, type } entries before committing them via the existing bulk merge API. **What this ships:** - `POST /api/brands/:domain/properties/parse` — auth-gated parse endpoint using Claude haiku; accepts text or URL input; returns `{ properties, count, truncated? }` - Brand builder "↑ Import" panel: paste-text and URL tabs, relationship dropdown (default: delegated), Parse → preview (count + first 5 identifiers + truncation warning) → Import confirm - Deduplicates against existing `singleBrandProperties` on confirm **Non-breaking justification:** new optional UI section and new POST endpoint with a `/parse` sub-path; existing `/properties` bulk-merge endpoint and all other routes are unchanged. **Safety mitigations applied:** - SSRF: `validateFetchUrl` + `safeFetch` (full DNS-rebind defence, redirect-hop re-validation); 15s `AbortSignal.timeout` - Unbounded buffering: streaming read with 1MB hard byte cap (not trusting Content-Length alone for chunked responses) - Prompt injection: user content fenced in `<content>` XML tags; preview-only — no write without explicit user confirm - Identifier length: 253-char DNS max enforced on LLM output - Input cap: 50k chars with `truncated: true` flag surfaced in UI **Pre-PR review:** - code-reviewer: approved — blockers fixed (streaming byte cap, identifier length guard, prompt injection fence, module-level client, relationship 400 on invalid values) - internal-tools-strategist: approved — truncation signal + streaming cap address the two original blockers; SSRF mitigation confirmed thorough; Parse/Preview/Import flow matches operator workflow > **Triage-managed PR.** This bot does not currently iterate on > review comments or PR conversation threads (only on the source > issue). To unblock: > > - **Push fixup commits directly:** `gh pr checkout <num>` → > fix → push. > - **Or re-trigger:** comment `/triage execute` on the source > issue. > > See [#3121](#3121) > for context. Session: https://claude.ai/code/session_01TC4wi4GMVsLo8e4mj51hze
…den SSRF error - Move getBrandForEdit before the URL fetch + LLM call so unauthorized users can't trigger outbound requests against arbitrary brand domains - Add explicit null guard on fetchResponse.body before calling getReader() - Return fixed string 'URL not allowed for security reasons' instead of leaking internal DNS error messages (harmonises with existing feed routes) Session: https://claude.ai/code/session_01TC4wi4GMVsLo8e4mj51hze
Pins the contract for the smart-paste parse endpoint at POST /api/brands/:domain/properties/parse — the gap the PR description explicitly called out as untested. 16 cases cover auth-gate-before-fetch, SSRF fixed-string error, input validation order, LLM output filtering (DNS 253-char cap, type allowlist, MAX_PROPERTIES cap, lowercasing), and the 50_000-char truncation flag. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Claude haiku consistently wraps the JSON response in a ```json fence despite the prompt asking for raw JSON, causing every paste to fall through to "Could not parse identifiers from input." Strip both language-tagged and bare fences before parsing. Caught end-to-end via Playwright on a real Claude call. Two new integration test cases pin the behaviour. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- Send `Accept-Encoding: identity` on the URL fetch so undici's auto gzip/br decode can't blow past the 1MB streaming cap (M1). - Escape literal `</content>` from fetched bodies before XML-fence interpolation; narrows prompt-injection surface from a hostile origin (M2). Output allowlist + DNS-length filter remain the load-bearing defenses. - Drop the safeFetch error message echo on 400; use the fixed string `Could not fetch URL` for parity with the SSRF rejection path. - Tighten the fence-strip regex: tolerate leading whitespace + CRLF, end-anchored so a fence mid-prose still falls through to the warning path. Adds 11 integration tests covering URL streaming branches, the full relationship enum, the Accept-Encoding header, `</content>` escape, and a negative fence-mid-prose case. Validated end-to-end with Playwright against a private/loopback URL — fixed string surfaces, no DNS internals leak. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Migrate POST /api/brands/:domain/properties/parse from text+JSON.parse to Anthropic tool_use with input_schema. The model emits typed args matching the schema; the route reads tool_use.input directly. Structurally eliminates the prompt-injection surface the prior `<content>...</content>` wrapper + `</content>` escape regex was trying (theatrically) to defend — security review flagged the escape as bypassable via Unicode slash variants and trivially via injection that doesn't need a closing tag at all. Deletes the fence-strip regex and the JSON.parse error path entirely. Tool definition encodes the type allowlist as a JSON-schema enum, so constraints land at the SDK layer too. tool_choice forces the tool; a defensive fall-through to the warning path covers the unlikely case where the SDK shape changes and no tool_use block surfaces. Output filter (DNS 253-char cap, type allowlist, MAX_PROPERTIES cap, lowercasing) remains as defense-in-depth. Tests rewritten: 26 cases, including new ones for the tool definition, tool_choice forcing, the missing-tool-use defensive branch, and a hostile-URL test confirming the `<content>` wrapper is gone and tool_choice still routes the model to extract_properties. Validated end-to-end with Playwright against real Claude haiku. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
bokelley
force-pushed
the
claude/issue-2180-smart-paste-property-import
branch
from
April 30, 2026 01:21
36aa008 to
db01c06
Compare
| safeFetch: mocks.safeFetch, | ||
| })); | ||
|
|
||
| import { initializeDatabase, closeDatabase, query } from '../../src/db/client.js'; |
bokelley
marked this pull request as ready for review
April 30, 2026 01:29
This was referenced Apr 30, 2026
bokelley
added a commit
that referenced
this pull request
Apr 30, 2026
…3598) Followup to PR #3396. The Accept-Encoding: identity request header disables undici auto-decompression, but a hostile server can ignore it and ship gzip/br/deflate anyway — undici still decodes, and the 1MB streaming cap measures decompressed bytes. A high-ratio bomb spikes memory before the cap fires. Now reject responses where Content-Encoding is anything other than identity (or absent) before reading the body. Server can't bypass. Also derive test fixture IDs from process.pid + Date.now() so parallel integration suites don't FK-conflict on shared organizations/users/ brands rows. Suggested by the nodejs-testing-expert review. 5 new tests cover gzip/br/deflate rejection (case-insensitive) plus an explicit identity acceptance case. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Apr 30, 2026
bokelley
added a commit
that referenced
this pull request
Apr 30, 2026
…ces (#3611) * refactor(property-enhancement): use Anthropic tool_use for analysis Mirrors the pattern from #3396 (smart-paste property parse). The analyze_property tool with input_schema constrains the model output to typed args; tool_choice forces it. The route reads tool_use.input directly — no JSON.parse, no fence stripping, no prompt-injection surface from text-output parsing. Exports analyzeProperty so the tool_use contract can be pinned by a unit test rather than indirectly through enhanceProperty (which pulls in WHOIS/DB). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(brand-classifier): use Anthropic tool_use for classification Mirrors the pattern from #3396. classify_brand tool with input_schema (enum-bounded keller_type and confidence) constrains the model output; tool_choice forces it. The route reads tool_use.input directly — no JSON.parse, no fence stripping. Auth-relevant: keller_type and confidence='high' gate brand-hierarchy membership inheritance in autoLinkByVerifiedDomain. The schema enum hardens the SDK layer; the runtime allowlist remains as the load-bearing defense. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(prospect-triage): use Anthropic tool_use for assessment Mirrors the pattern from #3396. assess_prospect tool with input_schema (enum-bounded action / owner / priority / company_type) constrains the model output; tool_choice forces it. The route reads tool_use.input directly — no JSON.parse, no fence stripping, no regex code-fence extraction. Removes the malformed-JSON throw path: with tool_use the SDK either returns a typed tool-use block or no block at all. The new no-tool-use throw is caught upstream by triageEmailDomain (returns action='skip', reason='assessment_error'), matching the prior failure semantics. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(brand-enrichment): use Anthropic tool_use for house expansion Mirrors the pattern from #3396. discover_sub_brands tool with input_schema (keller_type enum bounds returned brands to {sub_brand, endorsed}) constrains the model output; tool_choice forces it. The expandHouse path reads tool_use.input directly — no JSON.parse, no fence stripping. The downstream upsert already defaults keller_type to 'sub_brand' for any drift, so the schema enum + that default jointly bound what can land in the brands table. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * chore: changeset for claude tool_use sweep Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Oct 23, 2026
bokelley
added a commit
that referenced
this pull request
Oct 26, 2026
* chore(deps): migrate to @adcp/sdk 17.0.0-beta.0 (AdCP 3.3 beta)
Move to @adcp/sdk 17.0.0-beta.0, which pins the signed AdCP 3.3.0-beta.0
bundle and retains stable 3.2.7, 3.1.29 and 3.0.25 bundles. Move
@adcp/reporting-storage to 0.2.1-beta.0, the beta-train release whose peer
range accepts SDK 17 (0.1.0 requires ^16.0.0 and left the tree invalid).
- catalog runner: forward the SDK-native fixture_preparation phase in the
private audit record instead of a repo-shaped {disposition, phase}. The
supplied-hook refusal stays: SDK 16.5 added the preparation authorizer
(#3389), but this adapter's capability preflight still precedes it
(adcp-client#3435).
- learner and production guidance names the stable SDK on npm latest
(16.5.0); the choose-your-SDK page states SDK 17 beta support for the 3.3
beta. tests/helpers/sdk-checkpoint.cjs encodes the rule.
- tests: discovery failure is terminal since SDK 16.5 (adcp-client#3392);
context_key is echoed (#3396); the identity33 house-authority fix shipped
(#3388); a prerelease pin needs the exact advertised preview.
- SDK response-conformance baseline re-recorded under 17.0.0-beta.0 with
identical evidence apart from the version.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
* fix(training-agent): keep SDK 17 storyboard and preparation evidence native
- Routed requires: [multi_agent] storyboards: the runner's http loopback
made identity.brand_json_url schema-invalid (3.2+ needs https), and SDK
16.5+ fails discovery for capability-gated storyboards on invalid
capabilities. A harness-only TRAINING_AGENT_IDENTITY_URL keeps the public
https identity for those runs; deployments never set it.
- Catalog runner: when a native result omits producer records, fill the
SDK-native fixture_resolutions and fixture_preparation (protected captures
stripped) instead of a repo-shaped per-record failure.
- Reporting tests assert SDK 16.5+ native failed-preparation evidence.
- Known limitations: SDK #3395 is fixed upstream by adcp-client#3439, not
yet released.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
* docs(reference): add changeset for the SDK known-limitations update
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
* fix(training-agent): let test harnesses that disable rate limits skip the buyer OAuth limiter
SDK 17 opens more MCP sessions per client, which pushed the buyer OAuth
integration test's loopback traffic past the per-IP 60/min buyer limiter.
createTrainingAgentRouter({ disableRateLimit: true }) now also skips that
limiter; production keeps it (default on, unit-tested).
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.
Closes #2180
Network operators managing large publisher inventories can now paste a domain list (spreadsheet column, email, free-form text) or supply a public CSV / Google Sheets URL and have Claude extract structured
{ identifier, type }entries before committing them via the existing bulk merge API.What ships
Backend —
POST /api/brands/:domain/properties/parserequireAuth+getBrandForEditownership check fires before any outbound fetch or LLM spend{ input, input_type: 'text' | 'url', relationship? }validateFetchUrl(clean 400 before fetch) +safeFetchwith 15sAbortSignal.timeout; explicitbodynull guard; streaming read with 1MB hard byte cap (doesn't trustContent-Lengthfor chunked responses)truncated: truewhen hit{ identifier, type }[]; content wrapped in XML fence (<content>) to reduce prompt-injection surface; output validated againstVALID_PROPERTY_TYPES+ DNS 253-char max on identifiers{ properties, count, truncated? }; SSRF error returns fixed string (no DNS internals leaked)Frontend — brand builder import panel
delegated)singleBrandPropertiesthen calls existingPOST /api/brands/:domain/propertiesbulk mergeNot in scope for this PR:
properties_feed_urlstretch goal, Addie tool path, collection smart paste.Non-breaking justification
New UI section (hidden by default) and new POST endpoint at
/parsesub-path. The existing/propertiesbulk-merge endpoint and all other routes are unchanged. No schema modifications.Safety mitigations
getBrandForEditmoves before fetch; wrong-org users get 403 without triggering fetch or LLMvalidateFetchUrl+safeFetch(full DNS-rebind defence, redirect-hop re-validation)bodynull guard<content>XML tags; preview-only — no write without explicit user confirmVALID_PROPERTY_TYPESallowlist filtertruncated: trueflag surfaced as amber warning in preview UI'URL not allowed for security reasons'— no internal DNS messages exposedPre-PR review (2 passes)
Pass 1:
Pass 2 (second code-reviewer):
getBrandForEditbefore fetch block)body!non-null assertion → fixed (explicit null guard)content.innerHTMLwith integers safe but may trigger CodeQL scanner — noted for follow-upKnown gaps (follow-up issues):
content.innerHTMLuses integer values inline — safe but will likely require a CodeQL exception or node-building refactorSession: https://claude.ai/code/session_01TC4wi4GMVsLo8e4mj51hze