Skip to content

Commit

Permalink
Restrict connectionString to app service only (#3191)
Browse files Browse the repository at this point in the history
  • Loading branch information
heyams committed Jul 11, 2023
1 parent a66d51d commit 2b8a219
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private DiagnosticsHelper() {}
"APPLICATIONINSIGHTS_DIAGNOSTICS_OUTPUT_DIRECTORY";

// visible for testing
static volatile boolean useAppSvcRpIntegrationLogging;
public static volatile boolean useAppSvcRpIntegrationLogging;
private static volatile boolean useFunctionsRpIntegrationLogging;

private static volatile char rpIntegrationChar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,9 @@ static Configuration getConfigurationFromEnvVar(String json) {

Configuration configuration = getConfiguration(json, JsonOrigin.ENV_VAR);

if (configuration.connectionString != null) {
// restrict connection string in APPLICATIONINSIGHTS_CONFIGURATION_CONTENT for App Service only
if (configuration.connectionString != null
&& DiagnosticsHelper.useAppSvcRpIntegrationLogging()) {
throw new ConfigurationException(
"\"connectionString\" attribute is not supported inside of "
+ APPLICATIONINSIGHTS_CONFIGURATION_CONTENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
import com.microsoft.applicationinsights.agent.bootstrap.diagnostics.DiagnosticsHelper;
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.JmxMetric;
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.MatchType;
import com.microsoft.applicationinsights.agent.internal.configuration.Configuration.PreviewConfiguration;
Expand Down Expand Up @@ -104,6 +105,7 @@ void shouldParseFromEnvVar() throws IOException {

@Test
void shouldThrowFromEnvVarIfEmbeddedConnectionString() {
DiagnosticsHelper.useAppSvcRpIntegrationLogging = true;
String contentJson =
"{\"connectionString\":\"InstrumentationKey=55555555-5555-5555-5555-555555555555\","
+ "\"role\":{\"name\":\"testrole\"}}";
Expand Down

0 comments on commit 2b8a219

Please sign in to comment.