Skip to content

fix(templating): reject URI templates with a field reference inside the authority#25886

Open
thomasqueirozb wants to merge 3 commits into
masterfrom
fix/uri-template-partial-authority
Open

fix(templating): reject URI templates with a field reference inside the authority#25886
thomasqueirozb wants to merge 3 commits into
masterfrom
fix/uri-template-partial-authority

Conversation

@thomasqueirozb

Copy link
Copy Markdown
Member

Summary

Template::literal_prefix() truncates purely on the byte offset of the first {{, with no URI-grammar awareness. For a template like https://tenant.{{ env }}.example.com/, this yields a literal prefix of https://tenant., which UriChecker::from_prefix happily parses as authority tenant. — a baseline no real render can ever match, so every rendered event was silently dropped by the confinement check. This also affected templates with no separator at all before the field, e.g. https://api.internal{{ path }}.

This PR adds a build-time check: if there's no / after :// in the literal prefix, the field reference sits inside (or directly extends) the authority, and the template is now rejected at build time with a new BuildError::PartialUriAuthority instead of silently dropping every event at render time.

Vector configuration

sinks:
  http_sink:
    type: http
    inputs: ["*"]
    uri: "https://tenant.{{ env }}.example.com/"

How did you test this PR?

  • Added partial_uri_authority_rejected covering both the mid-authority case and the no-separator case.
  • Updated uri_authority_mismatch_rejected and no_static_uri_authority_rejected to use a template with a static host closed off by /, since the previous no-separator template is now rejected at build time.
  • cargo nextest run --no-default-features --lib template:: — all pass.
  • cargo clippy --no-default-features --lib — clean.

Change Type

  • Bug fix
  • New feature
  • Dependencies
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

NA

@thomasqueirozb
thomasqueirozb marked this pull request as ready for review July 17, 2026 18:00
@thomasqueirozb
thomasqueirozb requested a review from a team as a code owner July 17, 2026 18:00
@thomasqueirozb

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: dc9dd29e22

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/template.rs Outdated
prefix: String,
},

/// The literal prefix ends before the authority (host + optional port) is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: There are a lot of verbose comments. We should delete those. The snafu(display text is sufficient. And the partial_uri_authority_rejected test covers this.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fec8bcd5d0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

```yaml
sinks:
my_sink:
uri: "https://tenant-{{ env }}.example.com/"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fix the invalid remediation example

For users following this changelog, this replacement is still rejected by the new PartialUriAuthority check: its literal prefix is https://tenant-, which has no / after ://, so the field remains inside the hostname. The text says to keep the hostname static, but the example still puts {{ env }} in the host; use a static host with the dynamic value after a / instead.

Useful? React with 👍 / 👎.

```yaml
sinks:
my_sink:
uri: "https://api.internal{{ path }}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Mark no-separator path templates as breaking

For this example, existing configs can be functional today when path renders with a leading /: the old checker used base https://api.internal with path / and accepted rendered URLs like https://api.internal/v1. This change now fails those configs at build time, so describing them as only having “dropped every event” hides a real breaking upgrade case that should be marked or explained in the changelog.

Useful? React with 👍 / 👎.

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.

2 participants