Skip to content

fix(nuxt): security proxy prefers raw runtimeConfig/process.env strings over coerced values #1327

Description

@yamcodes

Summary

The Nuxt security proxy prefers raw string sources over the coerced validation target on both the client and server branches, so coercion (ADR 0002) is silently bypassed: a key typed as number returns a raw string at runtime.

Details

In packages/nuxt/src/create-env.ts (~lines 327–372), the proxy getter resolves schema keys in this order:

  • Client branch: runtimeEnvuseRuntimeConfig().public (raw strings) → __NUXT__.config.public (raw strings) → coerced target.
  • Server branch: runtimeEnvruntimeConfig[prop] / runtimeConfig.public[prop] (raw strings) → raw process.env[prop] → coerced target.

Severity on the server: prop in process.env is near-always true for schema keys (they were just validated from it), so the coerced target is effectively unreachable in the common path unless runtimeEnv explicitly owns the key. Server-side coercion is broken by default, not just in edge cases.

Fix direction

Coerce values before they enter the runtime payload rather than shipping a validator to the client. Implementation note: Nitro applies NUXT_PUBLIC_* runtime overrides as strings at boot, so the fix needs a boot-time coercion pass (e.g. a Nitro plugin), not just build-time injection.

Acceptance criteria

  • A key declared with a coercing schema (e.g. "string.numeric" with coerce) returns a number on both server and client, including when overridden via NUXT_PUBLIC_* at boot.
  • No validator code ships to the client bundle.
  • The existing test "dynamically resolve client keys from useRuntimeConfig" is updated to assert coerced values.
  • Regression tests cover the server branch's process.env fallback path.

Landing

Lands on dev first (bug fix affecting current users), then forward-port to v1 per the dual-tracking flow.

Part of #1105 (ADR 0015, #1326) — the aligned model's honesty claim is only as good as its weakest integration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    @arkenv/nuxtIssues or Pull Requests involving the Nuxt integration for ArkEnvbugSomething isn't workingready for agentFully specified, ready for immediate implementation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions