Skip to content

Improved metadata binding parsing and validation. #11101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

kshyju
Copy link
Member

@kshyju kshyju commented May 31, 2025

Improving how metadata binding is being read and used. Handles both worker indexing and host indexing cases.

Pull request checklist

IMPORTANT: Currently, changes must be backported to the in-proc branch to be included in Core Tools and non-Flex deployments.

  • Backporting to the in-proc branch is not required
    • Otherwise: Link to backporting PR
  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr - will follow
  • My changes do not require diagnostic events changes
    • Otherwise: I have added/updated all related diagnostic events and their documentation (Documentation issue linked to PR)
  • I have added all required tests (Unit tests, E2E tests)

@kshyju kshyju requested a review from a team as a code owner May 31, 2025 00:44
@@ -175,7 +176,7 @@ private static async Task<JObject> GetFunctionConfig(FunctionMetadata metadata,

private static async Task<JObject> GetFunctionConfigFromFile(string path)
{
return JObject.Parse(await FileUtility.ReadAsync(path));
return JObject.Parse(Sanitizer.Sanitize(await FileUtility.ReadAsync(path)));
Copy link
Member Author

Choose a reason for hiding this comment

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

synctrigger endpoint and /functions/{functionname} endpoint code reads the file if it is present. (Valid for custom handlers /non worker indexing use case).

@@ -257,7 +258,7 @@ internal FunctionMetadata ValidateBindings(IEnumerable<string> rawBindings, Func

foreach (string binding in rawBindings)
{
var deserializedObj = JsonConvert.DeserializeObject<JObject>(binding, _dateTimeSerializerSettings);
var deserializedObj = JsonConvert.DeserializeObject<JObject>(Sanitizer.Sanitize(binding), _dateTimeSerializerSettings);
Copy link
Member Author

Choose a reason for hiding this comment

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

This method gets executed in worker indexing use case.

@@ -41,6 +41,9 @@ public class SanitizerTests
[InlineData("test,aaa://aaa:[email protected]:1111,test", "test,[Hidden Credential],test")]
[InlineData(@"some text abc://abc:[email protected]:1111 some text abc://abc:[email protected]:1111 text", @"some text [Hidden Credential] some text [Hidden Credential] text")]
[InlineData(@"some text abc://abc:[email protected]:1111 some text AccountKey=heyyyyyyy text", @"some text [Hidden Credential] some text [Hidden Credential]")]
[InlineData("""{"queueName":"my-q-items","connection":"MyConnection","type":"queueTrigger","name":"qTrigger1","direction":"in"}""", "{\"queueName\":\"my-q-items\",\"connection\":\"MyConnection\",\"type\":\"queueTrigger\",\"name\":\"qTrigger1\",\"direction\":\"in\"}")]
[InlineData("""{"queueName":"my-q-items","connection":"DefaultEndpointsProtocol=https;AccountName=a;AccountKey=b/c==;EndpointSuffix=core.windows.net","type":"queueTrigger","name":"queueTrigger1","direction":"in"}""", "{\"queueName\":\"my-q-items\",\"connection\":\"[Hidden Credential]\",\"type\":\"queueTrigger\",\"name\":\"queueTrigger1\",\"direction\":\"in\"}")]

Copy link
Contributor

@surgupta-msft surgupta-msft Jun 5, 2025

Choose a reason for hiding this comment

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

Could this be a breaking change in some scenarios? Let's say, queue name is "key=myqueue" then we will replace it with "[Hidden Credential]". Will the function stop executing since we changed the queue name or is it only the Sync trigger response that is being sanitized (and it won't break any other component that depends on Sync trigger response)?

Copy link
Member Author

Choose a reason for hiding this comment

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

The functions are already in a broken state (not executing anything). The extension listener code throws when it is not able to resolve a valid app setting value from the value of these attributes (example code for service bus extension here). So this is not breaking anything.

Copy link
Contributor

@surgupta-msft surgupta-msft Jun 11, 2025

Choose a reason for hiding this comment

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

We are sanitizing the entire binding object for all scenarios and not just the exception cases. If any extension introduces (or already has) a binding property with name "password=" or "key=" (may not be good examples), they will be modified to [Hidden Credential] and the app can break.

In terms of binding values, I checked that the queue name and connection setting name cannot have "=" (but other bindings value may have "="), but they can have other characters like ":", so may be, we need to ensure that the Sanitizer class should never have tokens such as "key:", otherwise we will modify that value to [Hidden Credential]. A unit test should work for this scenario.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure I follow the last part of the comment. But for inputs like "one:two;three", Sanitizer returns the same value output.

Input Output
one:two;three one:two;three
one:a;two=three one:a;two=three
foo=bar foo=bar

If you meant something else, can you share an example input?

Copy link
Contributor

@surgupta-msft surgupta-msft Jun 11, 2025

Choose a reason for hiding this comment

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

Today, key=myvalue will return [HiddenCredential]. If in future, someone adds a token "key:" in Sanitizer, then
key:myvalue will also return [HiddenCredential]. This key:myvalue is a valid connection setting name. Let's also discuss this offline to make sure we don't have any confusion here.

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.

3 participants