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

Feature/signing #956

Draft
wants to merge 114 commits into
base: main
Choose a base branch
from
Draft

Feature/signing #956

wants to merge 114 commits into from

Conversation

HauklandJ
Copy link
Contributor

@HauklandJ HauklandJ commented Dec 6, 2024

Description

PR so that vi can publish an experimental package

Related Issue(s)

  • #{issue number}

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)

HauklandJ and others added 30 commits September 26, 2024 09:31
* adr for transaction handling

* scaffold signee service
… is supplied, authorize it as a write action. Move deletion of stale data elements to ProcessTaskInitializer.
* Expose endpoint for searching for person using ssn and last name.

* Use class and drop dto postfix.

* Move mapping to reponse class.

* Add success property to PersonSearchResult. Move person details into nested object.
* adds endpoint for getting an organisation from Enhetsregisteret

* renames OrganisationSearch -> Lookup
* temp

* feat: add phone and email to signee state

* split signee states on person/org, handle delegation before notification

* split signing notification and delegation to seperate services

* Move SigneeParty to Models folder

* update signeeConfig -> signeeParty

* split out method for processing signees to support retries

* restructure signeecontext, party and state

* update signing service to use new signingcontext structure

* split notification config based on the receiving system

* Make telemetry nullable in signing service.

* some more stuff

* Fix compilation error

* Touples in notification service. Sms number from registry. Store reason for sms/email failure.

* Extract SigningService interface. Various adjustments after mob session.

* For now: Add user action for initializing delegated signing.

---------

Co-authored-by: Bjørn Tore Gjerde <[email protected]>
* add model for delegation request

* add step builder for delegation request

* add scaffold for delegation client

* add scaffold to signing delegation service

* temp solution for const instead of magic strings

* add delegation client

* weird state

* update handling of party id to use party uuid

* rm sign delegate rights from access management client
# Conflicts:
#	src/Altinn.App.Core/Configuration/PlatformSettings.cs
#	src/Altinn.App.Core/Extensions/ServiceCollectionExtensions.cs
* update builder to standard set in correspondance (1/2)

* restructure: add builders folder

* formatting

* add TryGet method to retrieve app resource id

* cleanup

* formatting

* add custom exceptions

* use IOptions for plattformsettings

* simplify builder

* format

* trailing comma

* more formatting
* update controllers

* add 500 annotation for org lookup

* fix copy pasta

* update swagger

* lastname usage goes too deep (storage)

* update swagger

* update test paths

* use 200 OK when no hit

* typo

* log error

* format

* use the correct namespacing for the logger

* shorten method
@HauklandJ
Copy link
Contributor Author

/publish

Copy link

github-actions bot commented Mar 12, 2025

PR release:

⚙️ Building...
✅ Done!

@cammiida
Copy link
Contributor

/publish

Copy link

github-actions bot commented Mar 13, 2025

PR release:

⚙️ Building...
✅ Done!

@Altinn Altinn deleted a comment from github-actions bot Mar 13, 2025
@Altinn Altinn deleted a comment from github-actions bot Mar 13, 2025
#1161)

* Authorize process next as 'sign' when the process task type is signing and and no action was submitted. This is how storage authorizes it, and it means that the party that should run process next when everyone has signed, needs the 'sign' access right.

* Move process next authorization into separate class and define what kind of actions allow process next for each task type.
{
// Arrange
Instance instance = CreateInstance("task1", "data");
_httpContextAccessorMock.Setup(x => x.HttpContext).Returns((HttpContext?)null);

Check warning

Code scanning / CodeQL

Useless upcast Warning test

There is no need to upcast from
null
to
HttpContext
- the conversion can be done implicitly.

Copilot Autofix AI 4 days ago

To fix the problem, we need to remove the redundant cast (HttpContext?)null. This can be done by simply replacing (HttpContext?)null with null. This change should be made in the file test/Altinn.App.Core.Tests/Internal/Process/ProcessEngineAuthorizerTests.cs on line 260.

Suggested changeset 1
test/Altinn.App.Core.Tests/Internal/Process/ProcessEngineAuthorizerTests.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/test/Altinn.App.Core.Tests/Internal/Process/ProcessEngineAuthorizerTests.cs b/test/Altinn.App.Core.Tests/Internal/Process/ProcessEngineAuthorizerTests.cs
--- a/test/Altinn.App.Core.Tests/Internal/Process/ProcessEngineAuthorizerTests.cs
+++ b/test/Altinn.App.Core.Tests/Internal/Process/ProcessEngineAuthorizerTests.cs
@@ -259,3 +259,3 @@
         Instance instance = CreateInstance("task1", "data");
-        _httpContextAccessorMock.Setup(x => x.HttpContext).Returns((HttpContext?)null);
+        _httpContextAccessorMock.Setup(x => x.HttpContext).Returns(null);
 
EOF
@@ -259,3 +259,3 @@
Instance instance = CreateInstance("task1", "data");
_httpContextAccessorMock.Setup(x => x.HttpContext).Returns((HttpContext?)null);
_httpContextAccessorMock.Setup(x => x.HttpContext).Returns(null);

Copilot is powered by AI and may make mistakes. Always verify output.
_logger.LogDebug("User is authorized to perform action {Action}", checkedAction);
_logger.LogDebug(
"User successfully authorized to perform process next. Task ID: {CurrentTaskId}. Task type: {AltinnTaskType}. Action: {ProcessNextAction}.",
currentTaskId,

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

Copilot Autofix AI 4 days ago

To fix the problem, we need to sanitize the currentTaskId before logging it. This can be done by removing any newline characters from the currentTaskId to prevent log forging attacks. We will use the String.Replace method to achieve this.

  1. Identify the line where currentTaskId is logged (line 353).
  2. Sanitize the currentTaskId by replacing newline characters with an empty string before logging it.
Suggested changeset 1
src/Altinn.App.Api/Controllers/ProcessController.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/Altinn.App.Api/Controllers/ProcessController.cs b/src/Altinn.App.Api/Controllers/ProcessController.cs
--- a/src/Altinn.App.Api/Controllers/ProcessController.cs
+++ b/src/Altinn.App.Api/Controllers/ProcessController.cs
@@ -352,3 +352,3 @@
                 "User successfully authorized to perform process next. Task ID: {CurrentTaskId}. Task type: {AltinnTaskType}. Action: {ProcessNextAction}.",
-                currentTaskId,
+                currentTaskId?.Replace(Environment.NewLine, ""),
                 altinnTaskType,
EOF
@@ -352,3 +352,3 @@
"User successfully authorized to perform process next. Task ID: {CurrentTaskId}. Task type: {AltinnTaskType}. Action: {ProcessNextAction}.",
currentTaskId,
currentTaskId?.Replace(Environment.NewLine, ""),
altinnTaskType,
Copilot is powered by AI and may make mistakes. Always verify output.
_logger.LogDebug(
"User successfully authorized to perform process next. Task ID: {CurrentTaskId}. Task type: {AltinnTaskType}. Action: {ProcessNextAction}.",
currentTaskId,
altinnTaskType,

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

Copilot Autofix AI 4 days ago

To fix the problem, we need to ensure that any user input that is logged is properly sanitized. In this case, we should sanitize altinnTaskType before logging it. This can be done by using a method that removes or encodes any potentially harmful characters from the user input.

The best way to fix this without changing existing functionality is to introduce a sanitization method that removes newline characters and other potentially harmful characters from altinnTaskType before it is logged. We can create a utility method LogSanitizer.Sanitize to handle this sanitization.

Suggested changeset 1
src/Altinn.App.Api/Controllers/ProcessController.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/Altinn.App.Api/Controllers/ProcessController.cs b/src/Altinn.App.Api/Controllers/ProcessController.cs
--- a/src/Altinn.App.Api/Controllers/ProcessController.cs
+++ b/src/Altinn.App.Api/Controllers/ProcessController.cs
@@ -353,3 +353,3 @@
                 currentTaskId,
-                altinnTaskType,
+                LogSanitizer.Sanitize(altinnTaskType),
                 LogSanitizer.Sanitize(processNext?.Action ?? "none")
EOF
@@ -353,3 +353,3 @@
currentTaskId,
altinnTaskType,
LogSanitizer.Sanitize(altinnTaskType),
LogSanitizer.Sanitize(processNext?.Action ?? "none")
Copilot is powered by AI and may make mistakes. Always verify output.
{
_logger.LogError(
"Instance {InstanceId} has no current task. The process must be started before process next can be authorized.",
instance.Id

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

Copilot Autofix AI 4 days ago

To fix the problem, we need to sanitize the instance.Id before logging it. This can be done by removing any new line characters or other potentially harmful characters from the instance.Id. We can create a utility method to sanitize the input and use it before logging.

  1. Create a utility method Sanitize in a helper class to remove new line characters from the input.
  2. Use this method to sanitize instance.Id before logging it in ProcessEngineAuthorizer.cs.
Suggested changeset 1
src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.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/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs b/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
--- a/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
+++ b/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
@@ -39,3 +39,3 @@
                 "Instance {InstanceId} has no current task. The process must be started before process next can be authorized.",
-                instance.Id
+                LogSanitizer.Sanitize(instance.Id)
             );
EOF
@@ -39,3 +39,3 @@
"Instance {InstanceId} has no current task. The process must be started before process next can be authorized.",
instance.Id
LogSanitizer.Sanitize(instance.Id)
);
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +72 to +87
foreach (string actionToAuthorize in actionsThatAllowProcessNextForTaskType)
{
bool isActionAuthorized = await _authorizationService.AuthorizeAction(
new AppIdentifier(instance.AppId),
new InstanceIdentifier(instance),
_httpContext.User,
actionToAuthorize,
currentTaskId
);

if (isActionAuthorized)
{
isAnyActionAuthorized = true;
break;
}
}

Check notice

Code scanning / CodeQL

Missed opportunity to use Select Note

This foreach loop immediately
maps its iteration variable to another variable
- consider mapping the sequence explicitly using '.Select(...)'.

Copilot Autofix AI 4 days ago

To fix the problem, we will replace the foreach loop with a LINQ Select method to transform the sequence and then use the Any method to check if any action is authorized. This approach will make the code more readable by clearly expressing the intent to transform the sequence and check a condition.

  1. Replace the foreach loop with a LINQ Select method to transform the sequence.
  2. Use the Any method to check if any action is authorized.
  3. Ensure the asynchronous operations are handled correctly within the LINQ query.
Suggested changeset 1
src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.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/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs b/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
--- a/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
+++ b/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
@@ -70,19 +70,13 @@
 
-        var isAnyActionAuthorized = false;
-        foreach (string actionToAuthorize in actionsThatAllowProcessNextForTaskType)
-        {
-            bool isActionAuthorized = await _authorizationService.AuthorizeAction(
-                new AppIdentifier(instance.AppId),
-                new InstanceIdentifier(instance),
-                _httpContext.User,
-                actionToAuthorize,
-                currentTaskId
-            );
-
-            if (isActionAuthorized)
-            {
-                isAnyActionAuthorized = true;
-                break;
-            }
-        }
+        var isAnyActionAuthorized = await Task.WhenAny(
+            actionsThatAllowProcessNextForTaskType.Select(async actionToAuthorize =>
+                await _authorizationService.AuthorizeAction(
+                    new AppIdentifier(instance.AppId),
+                    new InstanceIdentifier(instance),
+                    _httpContext.User,
+                    actionToAuthorize,
+                    currentTaskId
+                )
+            )
+        ).ContinueWith(task => task.Result);
 
EOF
@@ -70,19 +70,13 @@

var isAnyActionAuthorized = false;
foreach (string actionToAuthorize in actionsThatAllowProcessNextForTaskType)
{
bool isActionAuthorized = await _authorizationService.AuthorizeAction(
new AppIdentifier(instance.AppId),
new InstanceIdentifier(instance),
_httpContext.User,
actionToAuthorize,
currentTaskId
);

if (isActionAuthorized)
{
isAnyActionAuthorized = true;
break;
}
}
var isAnyActionAuthorized = await Task.WhenAny(
actionsThatAllowProcessNextForTaskType.Select(async actionToAuthorize =>
await _authorizationService.AuthorizeAction(
new AppIdentifier(instance.AppId),
new InstanceIdentifier(instance),
_httpContext.User,
actionToAuthorize,
currentTaskId
)
)
).ContinueWith(task => task.Result);

Copilot is powered by AI and may make mistakes. Always verify output.

_logger.LogInformation(
"Process next performed without an action. Authorizing based on task type {AltinnTaskType}, which means using action(s) [{Actions}]. Authorization result: {IsAnyActionAuthorized}.",
altinnTaskType,

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

Copilot Autofix AI 4 days ago

To fix the problem, we need to sanitize the altinnTaskType before logging it. This can be done by removing any newline characters and other potentially harmful characters from the user input. We can create a utility method to sanitize the input and use it before logging.

  1. Create a utility method Sanitize in a new or existing utility class.
  2. Use this method to sanitize altinnTaskType before logging it.
Suggested changeset 1
src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.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/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs b/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
--- a/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
+++ b/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
@@ -89,4 +89,4 @@
         _logger.LogInformation(
-            "Process next performed without an action. Authorizing based on task type {AltinnTaskType}, which means using action(s) [{Actions}]. Authorization result: {IsAnyActionAuthorized}.",
-            altinnTaskType,
+            "Process next performed without an action. Authorizing based on task type {SanitizedAltinnTaskType}, which means using action(s) [{Actions}]. Authorization result: {IsAnyActionAuthorized}.",
+            LogSanitizer.Sanitize(altinnTaskType),
             string.Join(",", actionsThatAllowProcessNextForTaskType),
EOF
@@ -89,4 +89,4 @@
_logger.LogInformation(
"Process next performed without an action. Authorizing based on task type {AltinnTaskType}, which means using action(s) [{Actions}]. Authorization result: {IsAnyActionAuthorized}.",
altinnTaskType,
"Process next performed without an action. Authorizing based on task type {SanitizedAltinnTaskType}, which means using action(s) [{Actions}]. Authorization result: {IsAnyActionAuthorized}.",
LogSanitizer.Sanitize(altinnTaskType),
string.Join(",", actionsThatAllowProcessNextForTaskType),
Copilot is powered by AI and may make mistakes. Always verify output.
_logger.LogInformation(
"Process next performed without an action. Authorizing based on task type {AltinnTaskType}, which means using action(s) [{Actions}]. Authorization result: {IsAnyActionAuthorized}.",
altinnTaskType,
string.Join(",", actionsThatAllowProcessNextForTaskType),

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

Copilot Autofix AI 4 days ago

To fix the problem, we need to sanitize the user input before logging it. Specifically, we should ensure that the altinnTaskType and the actions derived from it do not contain any characters that could be used to forge log entries. We can use a method to sanitize the input by removing or encoding any potentially harmful characters.

  1. Create a method to sanitize the altinnTaskType and the actions derived from it.
  2. Use this method to sanitize the altinnTaskType before logging it.
  3. Ensure that the actions derived from altinnTaskType are also sanitized before logging.
Suggested changeset 1
src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.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/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs b/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
--- a/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
+++ b/src/Altinn.App.Core/Internal/Process/ProcessEngineAuthorizer.cs
@@ -89,5 +89,5 @@
         _logger.LogInformation(
-            "Process next performed without an action. Authorizing based on task type {AltinnTaskType}, which means using action(s) [{Actions}]. Authorization result: {IsAnyActionAuthorized}.",
-            altinnTaskType,
-            string.Join(",", actionsThatAllowProcessNextForTaskType),
+            "Process next performed without an action. Authorizing based on task type {SanitizedAltinnTaskType}, which means using action(s) [{SanitizedActions}]. Authorization result: {IsAnyActionAuthorized}.",
+            LogSanitizer.Sanitize(altinnTaskType),
+            string.Join(",", actionsThatAllowProcessNextForTaskType.Select(LogSanitizer.Sanitize)),
             isAnyActionAuthorized
EOF
@@ -89,5 +89,5 @@
_logger.LogInformation(
"Process next performed without an action. Authorizing based on task type {AltinnTaskType}, which means using action(s) [{Actions}]. Authorization result: {IsAnyActionAuthorized}.",
altinnTaskType,
string.Join(",", actionsThatAllowProcessNextForTaskType),
"Process next performed without an action. Authorizing based on task type {SanitizedAltinnTaskType}, which means using action(s) [{SanitizedActions}]. Authorization result: {IsAnyActionAuthorized}.",
LogSanitizer.Sanitize(altinnTaskType),
string.Join(",", actionsThatAllowProcessNextForTaskType.Select(LogSanitizer.Sanitize)),
isAnyActionAuthorized
Copilot is powered by AI and may make mistakes. Always verify output.
@bjorntore
Copy link
Contributor

/publish

Copy link

github-actions bot commented Mar 28, 2025

PR release:

⚙️ Building...
✅ Done!

* Add GetRoles method to Authorization client

* add GetAuthorizedOrganisations endpoint

* Add telemetry to authorization client GetRoles method

* extract method

* add mock for auth client

* format

* Add response dto

* update swagger snaphot

* update test setup to include new dependency

* add signing controller tests

* add signing service test

* mv GetAuthorizedOrganisations GetAuthorizedOrganisationSignees

* mv authorised authorized

* update swagger test expected snapshot

* use IAthenticationContext instead of IHttpContextAccessor

* use pdp multi part request to get key role organisations

* filter permitted

* cleanup

* update test

* add tempt tt02 debug logging

* do actions optionally on behalf of an org

* stringly typed

* rm unused using as this apparently crashed the github runners which are more strcit than building locally

* update swagger verified for snapshot

* add logging

* update test

* more logging

* found the issue...

* handle on behalf of

* rm getRoles from auth client as this is no longer used

* rm unused using

* rm solved TODO

* rm noisy logging

* make method static..
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
59.97% Condition Coverage on New Code (required ≥ 65%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

* Don't use string interpolation in logging message templates.

* Remove this unnecessary check for null.

* format

* rm todos

* condition always evaluates to true

* mark class as static

* rm todo comments

* 'int' should not be explicitly used as the underlying type of enum

* remove unused local variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-ignore This PR is a new feature and should not be cherry-picked onto release branches feature Label Pull requests with new features. Used when generation releasenotes kind/feature-request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants