Skip to content

Validate metadata paths in EC2MetadataUtils - #7551

Merged
Fred1155 merged 3 commits into
masterfrom
bole/validate-ec2-metadata-path
Nov 13, 2026
Merged

Fred1155 merged 3 commits into
masterfrom
bole/validate-ec2-metadata-path

Conversation

@Fred1155

Copy link
Copy Markdown
Contributor

EC2MetadataUtils` built the request URI by concatenating the configured endpoint and the caller-supplied path, without checking the path.

Motivation and Context

  • getItems, getData, and fetchData now require the path to start with /. Any other value, including null and empty, throws an SdkClientException before any request is sent, including the token request.
  • fetchData validates the path before the cache lookup.
  • The request URI is now built with SdkHttpUtils.appendUri.

Testing

Added unit tests to EC2MetadataUtilsTest:

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance improvement (non-breaking change which improves latency, throughput, or resource use)
  • Deprecation (marks existing functionality as deprecated)
  • Removal (removes previously deprecated functionality)
  • Documentation (changes to documentation only)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

AI tools

  • I wrote this pull request description myself, not with an AI tool
  • I have reviewed all changes in this pull request myself, including any generated by AI tools

License

  • I confirm that this pull request can be released under the Apache 2 license

Fred1155 and others added 3 commits November 13, 2026 21:13
## Changes

- `getData`, `getItems` and `fetchData` now throw `SdkClientException` when the path is `null` or does not start with `/`. The check runs before a metadata token is requested and before any connection is opened.
- The request URL is now built with `SdkHttpUtils.appendUri`, so exactly one `/` separates the configured endpoint and the path.
- `fetchData` with a `null` path now throws the same exception for both `force=true` and `force=false`. Before, the `force=false` case returned `null`.
- The `fetchData` javadoc now says the path must be absolute and start with `/`.
@Fred1155
Fred1155 requested a review from a team as a code owner November 13, 2026 21:47
@Fred1155
Fred1155 enabled auto-merge November 13, 2026 22:18
@Fred1155
Fred1155 added this pull request to the merge queue Nov 13, 2026
Merged via the queue into master with commit f37a2e5 Nov 13, 2026
13 of 14 checks passed
@github-actions

Copy link
Copy Markdown

This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants