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

fix: code scanning alert no. 175: Log Injection #347

Merged
merged 7 commits into from
Sep 30, 2024
14 changes: 14 additions & 0 deletions .github/actions/docker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ runs:
docker build . --target lyra-landing-page --tag lyra-landing-page:latest
shell: bash

# Cache for Trivy
- name: Set up Trivy cache directory
run: |
mkdir -p ~/.cache/trivy
shell: bash

- name: Cache Trivy DB
uses: actions/cache@v4
with:
path: ~/.cache/trivy
key: ${{ runner.os }}-trivy-db
restore-keys: |
${{ runner.os }}-trivy-db

- name: Publish to GHCR 📦
uses: ./.github/actions/docker/ghcr
with:
Expand Down
15 changes: 6 additions & 9 deletions .github/actions/docker/dockerhub/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ runs:
docker tag lyra-app:latest docker.io/${{ inputs.docker_hub_image }}-app:latest
docker tag lyra-landing-page:latest docker.io/${{ inputs.docker_hub_image }}-landing-page:${{ inputs.version }}
docker tag lyra-landing-page:latest docker.io/${{ inputs.docker_hub_image }}-landing-page:latest
docker push docker.io/${{ inputs.docker_hub_image }}:${{ inputs.version }}
docker push docker.io/${{ inputs.docker_hub_image }}:latest
docker push docker.io/${{ inputs.docker_hub_image }}-app:${{ inputs.version }}
docker push docker.io/${{ inputs.docker_hub_image }}-app:latest
docker push docker.io/${{ inputs.docker_hub_image }}-landing-page:${{ inputs.version }}
docker push docker.io/${{ inputs.docker_hub_image }}-landing-page:latest
docker push --all-tags docker.io/${{ inputs.docker_hub_image }}
docker push --all-tags docker.io/${{ inputs.docker_hub_image }}-app
docker push --all-tags docker.io/${{ inputs.docker_hub_image }}-landing-page
shell: bash

- name: Push non-production container image to Docker Hub ${{ inputs.non_prod_tag }}
Expand All @@ -64,7 +61,7 @@ runs:
docker.io/${{ inputs.image_name }}-app:${{ inputs.non_prod_tag }}
docker tag lyra-landing-page:latest \
docker.io/${{ inputs.image_name }}-landing-page:${{ inputs.non_prod_tag }}
docker push docker.io/${{ inputs.docker_hub_image }}:${{ inputs.non_prod_tag }}
docker push docker.io/${{ inputs.image_name }}-app:${{ inputs.non_prod_tag }}
docker push docker.io/${{ inputs.image_name }}-landing-page:${{ inputs.non_prod_tag }}
docker push --all-tags docker.io/${{ inputs.docker_hub_image }}
docker push --all-tags docker.io/${{ inputs.image_name }}-app
docker push --all-tags docker.io/${{ inputs.image_name }}-landing-page
shell: bash
30 changes: 21 additions & 9 deletions .github/actions/docker/ghcr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ inputs:
runs:
using: composite
steps:
# Trivy cache setup
- name: Set up Trivy cache directory
run: |
mkdir -p ~/.cache/trivy
shell: bash

- name: Cache Trivy DB
uses: actions/cache@v4
with:
path: ~/.cache/trivy
key: ${{ runner.os }}-trivy-db
restore-keys: |
${{ runner.os }}-trivy-db

# Vulnerability scanning
- name: OCI image vulnerability scanning
uses: aquasecurity/[email protected]
with:
Expand Down Expand Up @@ -55,12 +70,9 @@ runs:
docker tag lyra-app:latest ghcr.io/${{ inputs.image_name }}-app:latest
docker tag lyra-landing-page:latest ghcr.io/${{ inputs.image_name }}-landing-page:${{ inputs.version }}
docker tag lyra-landing-page:latest ghcr.io/${{ inputs.image_name }}-landing-page:latest
docker push ghcr.io/${{ inputs.image_name }}:${{ inputs.version }}
docker push ghcr.io/${{ inputs.image_name }}:latest
docker push ghcr.io/${{ inputs.image_name }}-app:${{ inputs.version }}
docker push ghcr.io/${{ inputs.image_name }}-app:latest
docker push ghcr.io/${{ inputs.image_name }}-landing-page:${{ inputs.version }}
docker push ghcr.io/${{ inputs.image_name }}-landing-page:latest
docker push --all-tags ghcr.io/${{ inputs.image_name }}
docker push --all-tags ghcr.io/${{ inputs.image_name }}-app
docker push --all-tags ghcr.io/${{ inputs.image_name }}-landing-page
shell: bash

- name: Push non-production container image to GHCR ${{ inputs.non_prod_tag }}
Expand All @@ -70,7 +82,7 @@ runs:
ghcr.io/${{ inputs.image_name }}:${{ inputs.non_prod_tag }}
docker tag lyra-app:latest ghcr.io/${{ inputs.image_name }}-app:${{ inputs.non_prod_tag }}
docker tag lyra-landing-page:latest ghcr.io/${{ inputs.image_name }}-landing-page:${{ inputs.non_prod_tag }}
docker push ghcr.io/${{ inputs.image_name }}:${{ inputs.non_prod_tag }}
docker push ghcr.io/${{ inputs.image_name }}-app:${{ inputs.non_prod_tag }}
docker push ghcr.io/${{ inputs.image_name }}-landing-page:${{ inputs.non_prod_tag }}
docker push --all-tags ghcr.io/${{ inputs.image_name }}
docker push --all-tags ghcr.io/${{ inputs.image_name }}-app
docker push --all-tags ghcr.io/${{ inputs.image_name }}-landing-page
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import jakarta.validation.constraints.Size
* @property email The email of the user. It must not be blank, must be a valid email address,
* and must be less than 255 characters.
* @property password The password of the user. It must not be blank and must be between 8 and 100 characters.
* @property firstname The firstname of the user. It must not be blank and must be between 3 and 100 characters.
* @property lastname The lastname of the user. It must not be blank and must be between 3 and 100 characters.
* @property firstname The firstname of the user. It must not be blank and must be between 1 and 100 characters.
* @property lastname The lastname of the user. It must not be blank and must be between 1 and 100 characters.
*/
data class RegisterUserRequest(
@field:NotBlank(message = "Email cannot be blank")
Expand All @@ -28,10 +28,10 @@ data class RegisterUserRequest(
@field:Size(min = 8, max = 100, message = "Password must be between 8 and 100 characters")
val password: String,
@field:NotBlank(message = "Firstname cannot be blank")
@field:Size(min = 3, max = 100, message = "Firstname must be between 3 and 100 characters")
@field:Size(min = 1, max = 100, message = "Firstname must be between 3 and 100 characters")
val firstname: String,
@field:NotBlank(message = "Lastname cannot be blank")
@field:Size(min = 3, max = 100, message = "Lastname must be between 3 and 100 characters")
@field:Size(min = 1, max = 100, message = "Lastname must be between 3 and 100 characters")
val lastname: String
) {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

override suspend fun create(user: User): User {
log.info("Saving user with email: {}", user.email.value)
log.info("Saving user with email: {}", user.email.value.replace("\n", "").replace("\r", ""))

val message = "Error creating user with email: ${user.email.value}"

Expand All @@ -51,8 +51,8 @@
} else {
log.debug(
"Trying to create user with email: {} and username: {}",
user.email.value,
user.username.value,
user.email.value.replace("\n", "").replace("\r", ""),
user.username.value.replace("\n", "").replace("\r", ""),
)
val userRepresentation = getUserRepresentation(user, credentialRepresentation)
userRepresentation.username = user.username.value
Expand All @@ -63,8 +63,8 @@
} catch (exception: BusinessRuleValidationException) {
log.error(
"Error creating user with email: {} and username: {}",
user.email.value,
user.username.value,
user.email.value.replace("\n", "").replace("\r", ""),
user.username.value.replace("\n", "").replace("\r", ""),
exception,
)
when (exception) {
Expand All @@ -74,7 +74,11 @@
else -> throw UserStoreException(message, exception)
}
} catch (exception: ClientErrorException) {
log.error("Error creating user with email: {}", user.email.value, exception)
log.error(
"Error creating user with email: {}",
user.email.value.replace("\n", "").replace("\r", ""),
exception,

Check warning on line 80 in apps/backend/src/main/kotlin/com/lyra/app/users/infrastructure/persistence/keycloak/KeycloakRepository.kt

View check run for this annotation

Codecov / codecov/patch

apps/backend/src/main/kotlin/com/lyra/app/users/infrastructure/persistence/keycloak/KeycloakRepository.kt#L77-L80

Added lines #L77 - L80 were not covered by tests
)
throw UserStoreException(message, exception)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private const val ERROR_CATEGORY = "AUTHENTICATION"

@Suppress("MultilineRawStringIndentation")
@AutoConfigureWebTestClient
class UserAuthenticatorControllerIntegrationTest : InfrastructureTestContainers() {
internal class UserAuthenticatorControllerIntegrationTest : InfrastructureTestContainers() {
// this user is created by default in Keycloak container (see demo-realm-test.json)
private val email = "[email protected]"
private val username = "john.doe"
Expand Down Expand Up @@ -190,7 +190,7 @@ class UserAuthenticatorControllerIntegrationTest : InfrastructureTestContainers(
.bodyValue(
"""
{
"username": "${user.email}",
"username": "${user.email.value}",
"password": "$randomPassword"
}
""".trimIndent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ internal class UserRegisterControllerIntegrationTest : InfrastructureTestContain
{
"email": "${faker.internet().emailAddress()}",
"password": "${Credential.generateRandomCredentialPassword()}",
"firstname": "a",
"firstname": "",
"lastname": "${faker.name().lastName()}"
}
""".trimIndent(),
Expand All @@ -213,7 +213,7 @@ internal class UserRegisterControllerIntegrationTest : InfrastructureTestContain
"email": "${faker.internet().emailAddress()}",
"password": "${Credential.generateRandomCredentialPassword()}",
"firstname": "${faker.name().firstName()}",
"lastname": "a"
"lastname": ""
}
""".trimIndent(),
)
Expand Down
Loading