Skip to content
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

chores/add authorization #117

Merged
merged 5 commits into from
Nov 29, 2024
Merged

chores/add authorization #117

merged 5 commits into from
Nov 29, 2024

Conversation

andreasisnes
Copy link
Collaborator

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

{
try
{
if (Request.ContentType.Contains("application/json"))

Check failure

Code scanning / CodeQL

User-controlled bypass of sensitive method High

This condition guards a sensitive
action
, but a
user-provided value
controls it.
This condition guards a sensitive
action
, but a
user-provided value
controls it.

Copilot Autofix AI 20 days ago

To fix the problem, we need to ensure that the decision to call AuthorizeJsonRequest or AuthorizeXmlRequest is not based solely on user-controlled data. Instead, we should validate the ContentType header securely before making the decision. One way to achieve this is to use a whitelist of allowed content types and ensure that the content type is valid before proceeding.

We will add a method to validate the content type and use this method in the Post action to decide which authorization method to call. This ensures that only valid content types are processed, reducing the risk of user-controlled bypass.

Suggested changeset 1
src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs
--- a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs
+++ b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs
@@ -39,2 +39,7 @@
 {
+    private bool IsValidContentType(string contentType)
+    {
+        var allowedContentTypes = new List<string> { "application/json", "application/xml" };
+        return allowedContentTypes.Any(contentType.Contains);
+    }
     /// <summary>
@@ -119,5 +124,12 @@
             {
-                if (Request.ContentType.Contains("application/json"))
+                if (IsValidContentType(Request.ContentType))
                 {
-                    return await AuthorizeJsonRequest(model, cancellationToken);
+                    if (Request.ContentType.Contains("application/json"))
+                    {
+                        return await AuthorizeJsonRequest(model, cancellationToken);
+                    }
+                    else
+                    {
+                        return await AuthorizeXmlRequest(model, cancellationToken);
+                    }
                 }
@@ -125,3 +137,3 @@
                 {
-                    return await AuthorizeXmlRequest(model, cancellationToken);
+                    return BadRequest("Unsupported content type");
                 }
EOF
@@ -39,2 +39,7 @@
{
private bool IsValidContentType(string contentType)
{
var allowedContentTypes = new List<string> { "application/json", "application/xml" };
return allowedContentTypes.Any(contentType.Contains);
}
/// <summary>
@@ -119,5 +124,12 @@
{
if (Request.ContentType.Contains("application/json"))
if (IsValidContentType(Request.ContentType))
{
return await AuthorizeJsonRequest(model, cancellationToken);
if (Request.ContentType.Contains("application/json"))
{
return await AuthorizeJsonRequest(model, cancellationToken);
}
else
{
return await AuthorizeXmlRequest(model, cancellationToken);
}
}
@@ -125,3 +137,3 @@
{
return await AuthorizeXmlRequest(model, cancellationToken);
return BadRequest("Unsupported content type");
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
private async Task<ActionResult> AuthorizeXmlRequest(XacmlRequestApiModel model, CancellationToken cancellationToken = default)
{
XacmlContextRequest request;
using (XmlReader reader = XmlReader.Create(new StringReader(model.BodyContent)))

Check warning

Code scanning / CodeQL

Missing XML validation Medium

This XML processing depends on a
user-provided value
without validation because there is no 'XmlReaderSettings' instance specifying schema validation.

Copilot Autofix AI 20 days ago

To fix the problem, we need to ensure that the user-provided XML content is validated against a known schema before processing it. This can be achieved by using XmlReaderSettings with the appropriate validation settings.

  1. Create an instance of XmlReaderSettings.
  2. Set the ValidationType to Schema.
  3. Add the known schema to the XmlSchemaSet of the XmlReaderSettings.
  4. Use the configured XmlReaderSettings when creating the XmlReader.
Suggested changeset 1
src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs
--- a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs
+++ b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/DecisionController.cs
@@ -262,3 +262,6 @@
             XacmlContextRequest request;
-            using (XmlReader reader = XmlReader.Create(new StringReader(model.BodyContent)))
+            XmlReaderSettings settings = new XmlReaderSettings();
+            settings.ValidationType = ValidationType.Schema;
+            settings.Schemas.Add("urn:my-schema", "path/to/your/schema.xsd");
+            using (XmlReader reader = XmlReader.Create(new StringReader(model.BodyContent), settings))
             {
EOF
@@ -262,3 +262,6 @@
XacmlContextRequest request;
using (XmlReader reader = XmlReader.Create(new StringReader(model.BodyContent)))
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add("urn:my-schema", "path/to/your/schema.xsd");
using (XmlReader reader = XmlReader.Create(new StringReader(model.BodyContent), settings))
{
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
[Authorize]
public async Task<ActionResult> ValidateSelectedParty(int userId, int partyId, CancellationToken cancellationToken = default)
{
if (userId == 0 || partyId == 0)

Check failure

Code scanning / CodeQL

User-controlled bypass of sensitive method High

This condition guards a sensitive
action
, but a
user-provided value
controls it.
This condition guards a sensitive
action
, but a
user-provided value
controls it.
This condition guards a sensitive
action
, but a
user-provided value
controls it.
This condition guards a sensitive
action
, but a
user-provided value
controls it.

Copilot Autofix AI 20 days ago

To fix the problem, we need to ensure that the userId parameter is validated against the authenticated user's ID before performing any sensitive actions. This can be done by moving the validation of userId before the condition userId == 0 || partyId == 0. This way, we ensure that the userId is properly authenticated before proceeding with any further checks.

Suggested changeset 1
src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs
--- a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs
+++ b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs
@@ -86,2 +86,8 @@
         {
+            int? authnUserId = User.GetUserIdAsInt();
+            if (userId != authnUserId)
+            {
+                return Forbid();
+            }
+
             if (userId == 0 || partyId == 0)
@@ -93,8 +99,2 @@
             {
-                int? authnUserId = User.GetUserIdAsInt();
-                if (userId != authnUserId)
-                {
-                    return Forbid();
-                }
-            
                 return Ok(await ValidateSelectedAuthorizedParty(partyId, cancellationToken));
EOF
@@ -86,2 +86,8 @@
{
int? authnUserId = User.GetUserIdAsInt();
if (userId != authnUserId)
{
return Forbid();
}

if (userId == 0 || partyId == 0)
@@ -93,8 +99,2 @@
{
int? authnUserId = User.GetUserIdAsInt();
if (userId != authnUserId)
{
return Forbid();
}

return Ok(await ValidateSelectedAuthorizedParty(partyId, cancellationToken));
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
[Authorize]
public async Task<ActionResult> ValidateSelectedParty(int userId, int partyId, CancellationToken cancellationToken = default)
{
if (userId == 0 || partyId == 0)

Check failure

Code scanning / CodeQL

User-controlled bypass of sensitive method High

This condition guards a sensitive
action
, but a
user-provided value
controls it.

Copilot Autofix AI 20 days ago

To fix the problem, we need to ensure that the validation logic is not bypassed based on user-controlled input. Instead of checking if userId is zero, we should validate the userId against the authenticated user's ID at the beginning of the method. This way, we can ensure that the user is authorized to perform the action without relying on user-controlled values.

  1. Remove the check if (userId == 0 || partyId == 0) and replace it with a validation against the authenticated user's ID.
  2. Ensure that the method proceeds with the validation logic only if the userId matches the authenticated user's ID.
Suggested changeset 1
src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs
--- a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs
+++ b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs
@@ -86,5 +86,6 @@
         {
-            if (userId == 0 || partyId == 0)
+            int? authnUserId = User.GetUserIdAsInt();
+            if (userId != authnUserId || partyId == 0)
             {
-                return NotFound();
+                return Forbid();
             }
@@ -93,8 +94,2 @@
             {
-                int? authnUserId = User.GetUserIdAsInt();
-                if (userId != authnUserId)
-                {
-                    return Forbid();
-                }
-            
                 return Ok(await ValidateSelectedAuthorizedParty(partyId, cancellationToken));
EOF
@@ -86,5 +86,6 @@
{
if (userId == 0 || partyId == 0)
int? authnUserId = User.GetUserIdAsInt();
if (userId != authnUserId || partyId == 0)
{
return NotFound();
return Forbid();
}
@@ -93,8 +94,2 @@
{
int? authnUserId = User.GetUserIdAsInt();
if (userId != authnUserId)
{
return Forbid();
}

return Ok(await ValidateSelectedAuthorizedParty(partyId, cancellationToken));
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
[Authorize]
public async Task<ActionResult> ValidateSelectedParty(int userId, int partyId, CancellationToken cancellationToken = default)
{
if (userId == 0 || partyId == 0)

Check failure

Code scanning / CodeQL

User-controlled bypass of sensitive method High

This condition guards a sensitive
action
, but a
user-provided value
controls it.

Copilot Autofix AI 20 days ago

To fix this issue, we need to ensure that the validation logic is not bypassed based on user-controlled data. Instead of returning NotFound when partyId is 0, we should handle this case more securely. One way to do this is to validate the partyId before proceeding with the rest of the logic and ensure that it is a valid, non-zero value.

We will:

  1. Add a method to validate the partyId and ensure it is a valid, non-zero value.
  2. Use this method to validate the partyId before proceeding with the rest of the logic in the ValidateSelectedParty method.
Suggested changeset 1
src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs
--- a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs
+++ b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Controllers/PartiesController.cs
@@ -86,3 +86,3 @@
         {
-            if (userId == 0 || partyId == 0)
+            if (userId == 0 || !IsValidPartyId(partyId))
             {
@@ -118,2 +118,8 @@
         }
+
+        private bool IsValidPartyId(int partyId)
+        {
+            // Add logic to validate the partyId, e.g., check if it is non-zero and exists in the database
+            return partyId > 0;
+        }
     }
EOF
@@ -86,3 +86,3 @@
{
if (userId == 0 || partyId == 0)
if (userId == 0 || !IsValidPartyId(partyId))
{
@@ -118,2 +118,8 @@
}

private bool IsValidPartyId(int partyId)
{
// Add logic to validate the partyId, e.g., check if it is non-zero and exists in the database
return partyId > 0;
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
{
stream.Position = 0;
XacmlPolicy policy;
using (XmlReader reader = XmlReader.Create(stream))

Check warning

Code scanning / CodeQL

Missing XML validation Medium

This XML processing depends on a
user-provided value
without validation because there is no 'XmlReaderSettings' instance specifying schema validation.
This XML processing depends on a
user-provided value
without validation because there is no 'XmlReaderSettings' instance specifying schema validation.

Copilot Autofix AI 20 days ago

To fix the problem, we need to ensure that the XML data is validated against a known schema before processing it. This involves creating an XmlReaderSettings instance with the ValidationType set to Schema and specifying the schema to validate against. We also need to ensure that the ValidationFlags do not include ProcessInlineSchema or ProcessSchemaLocation to prevent users from providing their own schemas.

Steps to fix:

  1. Create an XmlReaderSettings instance.
  2. Set the ValidationType to Schema.
  3. Add the known schema to the Schemas property of the XmlReaderSettings instance.
  4. Ensure that ValidationFlags do not include ProcessInlineSchema or ProcessSchemaLocation.
  5. Use this XmlReaderSettings instance when creating the XmlReader.
Suggested changeset 1
src/apps/Altinn.Authorization/src/Altinn.Authorization/Helpers/PolicyHelper.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Helpers/PolicyHelper.cs b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Helpers/PolicyHelper.cs
--- a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Helpers/PolicyHelper.cs
+++ b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Helpers/PolicyHelper.cs
@@ -262,3 +262,8 @@
             XacmlPolicy policy;
-            using (XmlReader reader = XmlReader.Create(stream))
+            XmlReaderSettings settings = new XmlReaderSettings();
+            settings.ValidationType = ValidationType.Schema;
+            settings.Schemas.Add("urn:my-schema", "my.xsd"); // Replace with actual schema details
+            settings.ValidationFlags &= ~XmlSchemaValidationFlags.ProcessInlineSchema;
+            settings.ValidationFlags &= ~XmlSchemaValidationFlags.ProcessSchemaLocation;
+            using (XmlReader reader = XmlReader.Create(stream, settings))
             {
EOF
@@ -262,3 +262,8 @@
XacmlPolicy policy;
using (XmlReader reader = XmlReader.Create(stream))
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add("urn:my-schema", "my.xsd"); // Replace with actual schema details
settings.ValidationFlags &= ~XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationFlags &= ~XmlSchemaValidationFlags.ProcessSchemaLocation;
using (XmlReader reader = XmlReader.Create(stream, settings))
{
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
{
if (!DelegationHelper.PolicyContainsMatchingRule(appPolicy, rule))
{
_logger.LogWarning("Matching rule not found in app policy. Action might not exist for Resource, or Resource itself might not exist. Delegation policy path: {policyPath}. Rule: {rule}", policyPath, rule);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.

Copilot Autofix AI 20 days ago

To fix the problem, we need to sanitize the rule object before logging it. Since the log entries are plain text, we should remove any new line characters from the rule object to prevent log forging. This can be done using the String.Replace method or a similar approach.

The best way to fix the problem without changing existing functionality is to sanitize the rule object right before it is logged. We will replace new line characters in the rule object with an empty string to ensure that no new lines are introduced into the log.

Suggested changeset 1
src/apps/Altinn.Authorization/src/Altinn.Authorization/Services/Implementation/PolicyAdministrationPoint.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Services/Implementation/PolicyAdministrationPoint.cs b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Services/Implementation/PolicyAdministrationPoint.cs
--- a/src/apps/Altinn.Authorization/src/Altinn.Authorization/Services/Implementation/PolicyAdministrationPoint.cs
+++ b/src/apps/Altinn.Authorization/src/Altinn.Authorization/Services/Implementation/PolicyAdministrationPoint.cs
@@ -192,3 +192,4 @@
                 {
-                    _logger.LogWarning("Matching rule not found in app policy. Action might not exist for Resource, or Resource itself might not exist. Delegation policy path: {policyPath}. Rule: {rule}", policyPath, rule);
+                    string sanitizedRule = rule.ToString().Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
+                    _logger.LogWarning("Matching rule not found in app policy. Action might not exist for Resource, or Resource itself might not exist. Delegation policy path: {policyPath}. Rule: {sanitizedRule}", policyPath, sanitizedRule);
                     return false;
EOF
@@ -192,3 +192,4 @@
{
_logger.LogWarning("Matching rule not found in app policy. Action might not exist for Resource, or Resource itself might not exist. Delegation policy path: {policyPath}. Rule: {rule}", policyPath, rule);
string sanitizedRule = rule.ToString().Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogWarning("Matching rule not found in app policy. Action might not exist for Resource, or Resource itself might not exist. Delegation policy path: {policyPath}. Rule: {sanitizedRule}", policyPath, sanitizedRule);
return false;
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
XmlDocument requestDocument = new XmlDocument();
requestDocument.Load(Path.Combine(requestPath, requestDocumentTitle));
XacmlContextRequest contextRequest;
using (XmlReader reader = XmlReader.Create(new StringReader(requestDocument.OuterXml)))

Check warning

Code scanning / CodeQL

Missing XML validation Medium test

This XML processing depends on a
user-provided value
without validation because there is no 'XmlReaderSettings' instance specifying schema validation.

Copilot Autofix AI 20 days ago

To fix the problem, we need to ensure that the XML data is validated against a known schema before it is processed. This involves creating an instance of XmlReaderSettings with the appropriate validation settings and using it when creating the XmlReader.

  1. Create an instance of XmlReaderSettings.
  2. Set the ValidationType property to Schema.
  3. Add the known schema to the Schemas property of the XmlReaderSettings instance.
  4. Use the XmlReaderSettings instance when creating the XmlReader.
Suggested changeset 1
src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/ContextHandlerMock.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/ContextHandlerMock.cs b/src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/ContextHandlerMock.cs
--- a/src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/ContextHandlerMock.cs
+++ b/src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/ContextHandlerMock.cs
@@ -270,3 +270,6 @@
             XacmlContextRequest contextRequest;
-            using (XmlReader reader = XmlReader.Create(new StringReader(requestDocument.OuterXml)))
+            XmlReaderSettings settings = new XmlReaderSettings();
+            settings.ValidationType = ValidationType.Schema;
+            settings.Schemas.Add("urn:my-schema", "path/to/your/schema.xsd"); // Update with actual schema details
+            using (XmlReader reader = XmlReader.Create(new StringReader(requestDocument.OuterXml), settings))
             {
EOF
@@ -270,3 +270,6 @@
XacmlContextRequest contextRequest;
using (XmlReader reader = XmlReader.Create(new StringReader(requestDocument.OuterXml)))
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add("urn:my-schema", "path/to/your/schema.xsd"); // Update with actual schema details
using (XmlReader reader = XmlReader.Create(new StringReader(requestDocument.OuterXml), settings))
{
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

policyDocument.Load(Path.Combine(policyPath, policyDocumentTitle));
XacmlPolicy policy;
using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))

Check warning

Code scanning / CodeQL

Missing XML validation Medium test

This XML processing depends on a
user-provided value
without validation because there is no 'XmlReaderSettings' instance specifying schema validation.
This XML processing depends on a
user-provided value
without validation because there is no 'XmlReaderSettings' instance specifying schema validation.
This XML processing depends on a
user-provided value
without validation because there is no 'XmlReaderSettings' instance specifying schema validation.

Copilot Autofix AI 20 days ago

To fix the problem, we need to validate the XML data against a known schema using XmlReaderSettings. This involves:

  1. Creating an instance of XmlReaderSettings.
  2. Setting the ValidationType to Schema.
  3. Adding the known schema to the Schemas property of XmlReaderSettings.
  4. Using this XmlReaderSettings instance when creating the XmlReader.

We will modify the ParsePolicy method to include these changes.

Suggested changeset 1
src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/PolicyRetrievalPointMock.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/PolicyRetrievalPointMock.cs b/src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/PolicyRetrievalPointMock.cs
--- a/src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/PolicyRetrievalPointMock.cs
+++ b/src/apps/Altinn.Authorization/test/Altinn.Authorization.Tests/MockServices/PolicyRetrievalPointMock.cs
@@ -182,3 +182,6 @@
             XacmlPolicy policy;
-            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
+            XmlReaderSettings settings = new XmlReaderSettings();
+            settings.ValidationType = ValidationType.Schema;
+            settings.Schemas.Add("urn:my-schema", "path/to/your/schema.xsd"); // Update with actual schema details
+            using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml), settings))
             {
EOF
@@ -182,3 +182,6 @@
XacmlPolicy policy;
using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml)))
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add("urn:my-schema", "path/to/your/schema.xsd"); // Update with actual schema details
using (XmlReader reader = XmlReader.Create(new StringReader(policyDocument.OuterXml), settings))
{
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
return new X509SigningCredentials(certIssuer, SecurityAlgorithms.RsaSha256);
}

X509Certificate2 cert = new X509Certificate2("selfSignedTestCertificate.pfx", "qwer1234");

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "qwer1234" flows to the
password
parameter in
object creation of type X509Certificate2
.
@andreasisnes andreasisnes merged commit 7667e30 into main Nov 29, 2024
10 of 11 checks passed
@andreasisnes andreasisnes deleted the chores/add-authorization branch November 29, 2024 12:58
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.

1 participant