Repository navigation
Reject configuration property names with a repeated separator - #52303
Open
sharanggupta wants to merge 2 commits into
Open
sharanggupta wants to merge 2 commits into
sharanggupta wants to merge 2 commits into
Conversation
ConfigurationPropertyName.elementsOf already rejects a name with a
leading or trailing dot, but a repeated dot anywhere in the name
(e.g. "foo..bar") was accepted: ElementsParser.add silently drops
the empty element produced between the two separators, so
"foo..bar" and "foo...bar" both parse as identical to "foo.bar",
and ConfigurationPropertyName.isValid("foo..bar") returns true.
This matters beyond strict validation: the same ElementsParser is
used by the lenient adapt(...) path that SpringIterableConfiguration
PropertySource relies on to map raw property-source keys onto
ConfigurationPropertyNames for relaxed binding. Two distinct raw keys
that differ only by an accidental repeated separator (a typo in a
properties file, or any code that builds a key by concatenation)
collapse onto the same name there too, and the source's Cache keeps
whichever one happens to land first in an unordered HashSet - so one
of two real, distinct configuration values is silently and
non-deterministically dropped, with no exception or log output.
This change closes the gap in the strict of()/isValid() API by
extending the existing leading/trailing-dot check to also reject an
internal repeated separator, consistently with how the name is
already documented and tested to behave at the start/end of the
string.
I want to be upfront that this does not, on its own, change the
behavior of the lenient adapt(...) path, since that method is
intentionally more permissive than of() (per its own Javadoc) and
silently stripping or rejecting input is core to its contract; I did
not want to unilaterally change that shared, more permissive code
path without knowing which behavior the team would prefer for it
(reject the key outright during relaxed-binding iteration, merge
deterministically, or something else). Happy to follow up on that
once the team has a view - I can reproduce the relaxed-binding
collision with a small Binder-based test case if useful.
Added ConfigurationPropertyNameTests.ofNameShouldNotContainDoubleDot
and extended isValidWhenNotValidShouldReturnFalse to cover this.
core:spring-boot test suite (965 tests, properties/binder packages)
green, no regressions.
Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
…pertyname-repeated-separator # Conflicts: # core/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java # core/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java
This branch has not been deployed
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.
ConfigurationPropertyName.elementsOfalready rejects a name with a leading or trailing dot (ConfigurationPropertyName.of(".foo")/of("foo.")both throwInvalidConfigurationPropertyNameException), but a repeated dot anywhere else in the name was silently accepted:The root cause is in
ElementsParser.add: a repeated separator produces an empty element between the two dots, andaddsilently drops any empty element instead of flagging it, so"foo..bar"(or any number of repeated dots) parses as indistinguishable from"foo.bar".This isn't just a strict-validation gap. The same
ElementsParserbacks the lenientadapt(...)path thatSpringIterableConfigurationPropertySourceuses to map raw property-source keys ontoConfigurationPropertyNames for relaxed binding. Two distinct raw keys that differ only by an accidental repeated separator — a typo in a.propertiesfile, or any code that builds a key by concatenation — collapse onto the same name there too, and the source'sCachekeeps whichever raw key happens to land first in an unorderedHashSet, so one of two real, distinct configuration values is silently and non-deterministically dropped, with no exception or log output:(I ran this 5+ times with the insertion order swapped; the "survivor" is not insertion-order-dependent, it's purely
HashSetiteration order.)This PR closes the gap in the strict
of()/isValid()API by extending the existing leading/trailing-dot check to also reject an internal repeated separator, consistent with how the name is already documented and tested to behave at the start/end of the string.I want to be upfront that this does not, on its own, change the behavior of the lenient
adapt(...)path, since that method is intentionally more permissive thanof()(per its own Javadoc: "more lenient thanof()in that it allows mixed case names... other invalid characters are stripped out during parsing"), and I didn't want to unilaterally change that shared, more-permissive code path without knowing which behavior the team would prefer there — reject the key outright during relaxed-binding iteration, pick a value deterministically instead of by hash order, or something else. Happy to follow up with whichever direction you'd prefer; theBinderreproduction above should still be useful context either way.Added
ConfigurationPropertyNameTests.ofNameShouldNotContainDoubleDotand extendedisValidWhenNotValidShouldReturnFalseto cover this. Ran the fullcore:spring-bootproperties/binder test packages locally (965 tests) — green, no regressions.