#3389·metaflow

validate_aws_tag only checks the first character of tag keys and values

Author: eyosi1239Created Sep 29, 2026Updated Sep 29, 2026

validate_aws_tag in metaflow/plugins/aws/aws_utils.py uses re.match(PERMITTED, key) and the equivalent check for values. PERMITTED matches a single character, so a permitted first character lets any later characters pass unchecked. This gap was noted as follow-up work in #3366. I couldn't find a subsequent issue or fix.

Thanks @Anai-Guo for flagging this. Happy to defer if you were planning to pick it up otherwise I'd like to take it. cc @saikonen since you reviewed #3366.

Steps to reproduce

python
from metaflow.plugins.aws.aws_utils import validate_aws_tag

validate_aws_tag("a!", "valid")    # returns without error
validate_aws_tag("valid", "b#$%")  # returns without error
validate_aws_tag("!a", "valid")    # raises MetaflowException

Expected and actual behavior

Expected: A character outside the validator's permitted set raises MetaflowException wherever it occurs in a key or value.

Actual: Only the first character is checked. Later characters outside the permitted set pass.

Impact

When Batch tag emission is enabled, user-supplied tags that pass validation are added to the AWS Batch submit_job request without going through Metaflow's tag sanitizer (which is only applied to the built-in metadata tags). AWS may accept or reject a given tag, so this bypasses the intended early validation and can push any rejection to job submission time.

validate_aws_tag is also used for Step Functions tags (step_functions_cli.py), so the same validation gap applies there.

The existing test_validate_aws_tag never passes a disallowed character after the first position, which is why this wasn't caught.

Proposed approach

Match the entire key and value against the existing permitted character set, with parametrized tests for disallowed characters at the start, middle, and end of each, and separate tests for empty keys and values.

The validator already enforces the 128-character key and 256-character value maximums. A full-string + match on keys would also require a non-empty key. For values, + preserves current behavior (empty values rejected), while * would allow empty values, which AWS Batch permits.

Before opening a PR, I'd appreciate maintainer input on two behavirs changes:

  1. Should tags that currently pass because of this bug start raising immediately, or should there be a warning first?
  2. Should the fix also allow empty tag values?

Environment

  • OS: macOS Tahoe 26.5.2
  • Python: 3.12.14
  • Metaflow: master (8b500daa)
  • Integrations: AWS Batch, Step Functions