Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ workflows:
branches:
only:
- develop
- pm-2539

# Production builds are exectuted only on tagged commits to the
# master branch.
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/trivy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Trivy Scanner

permissions:
contents: read
security-events: write
on:
push:
branches:
- main
- dev
pull_request:
jobs:
trivy-scan:
name: Use Trivy
runs-on: ubuntu-24.04

Choose a reason for hiding this comment

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

[⚠️ maintainability]
Consider using ubuntu-latest instead of ubuntu-24.04 to ensure the workflow benefits from the latest security patches and updates. This can help avoid potential issues with outdated dependencies or vulnerabilities.

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Trivy scanner in repo mode
uses: aquasecurity/trivy-action@0.33.1
with:
scan-type: "fs"
ignore-unfixed: true
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL,HIGH,UNKNOWN"
scanners: vuln,secret,misconfig,license
github-pat: ${{ secrets.GITHUB_TOKEN }}

Choose a reason for hiding this comment

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

[❗❗ security]
Ensure that the GITHUB_TOKEN secret is configured with the necessary permissions for this workflow. If additional permissions are required beyond the default, they should be explicitly set in the permissions section.


- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: "trivy-results.sarif"
2 changes: 1 addition & 1 deletion src/auth/guards/roles.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class RolesGuard implements CanActivate {
.map((s: string) => s.trim())
.filter(Boolean);

const scopeOk = fallbackScopes.every((s) => scopes.includes(s));
const scopeOk = fallbackScopes.some((s) => scopes.includes(s));

Choose a reason for hiding this comment

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

[❗❗ correctness]
The change from every to some alters the logic to allow access if any fallback scope matches, rather than requiring all to match. Ensure this change aligns with the intended authorization logic, as it could potentially broaden access permissions.

if (scopeOk) return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/auth/guards/scopes.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ScopesGuard implements CanActivate {
.map((s: string) => s.trim())
.filter(Boolean);

const ok = required.every((s) => scopes.includes(s));
const ok = required.some((s) => scopes.includes(s));

Choose a reason for hiding this comment

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

[❗❗ correctness]
Changing from every to some alters the logic from requiring all scopes to match to requiring only one. Ensure this change aligns with the intended authorization logic, as it could inadvertently grant access with insufficient permissions.

if (ok) return true;

const fallbackRoles = this.reflector.getAllAndOverride<string[]>(ROLES_KEY, [
Expand Down
9 changes: 8 additions & 1 deletion src/common/members-lookup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ export class MembersLookupService {
return;
}
// Create a dedicated Prisma client targeting the members DB
this.client = new PrismaClient({ datasources: { db: { url } } });
this.client = new PrismaClient({
transactionOptions: {
timeout: process.env.BA_SERVICE_PRISMA_TIMEOUT

Choose a reason for hiding this comment

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

[⚠️ correctness]
The parseInt function is used without specifying a radix, which defaults to 10 in this context. However, it's a good practice to always specify the radix explicitly to avoid potential issues in other environments. Consider using parseInt(process.env.BA_SERVICE_PRISMA_TIMEOUT, 10).

Choose a reason for hiding this comment

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

[❗❗ security]
The environment variable BA_SERVICE_PRISMA_TIMEOUT is parsed as an integer and used as a timeout value. Ensure that this environment variable is always set to a valid integer to prevent runtime errors. Consider adding validation logic to handle invalid or missing values more gracefully.

? parseInt(process.env.BA_SERVICE_PRISMA_TIMEOUT, 10)
: 10000,
},
datasources: { db: { url } }
});
this.initialized = true;
}

Expand Down
10 changes: 10 additions & 0 deletions src/common/prisma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ import { PrismaClient } from "@prisma/client";

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
constructor() {
super({
transactionOptions: {
timeout: process.env.BA_SERVICE_PRISMA_TIMEOUT

Choose a reason for hiding this comment

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

[❗❗ correctness]
Consider validating the environment variable process.env.BA_SERVICE_PRISMA_TIMEOUT before using it. If it is not a valid number, parseInt will return NaN, which could lead to unexpected behavior. You might want to add a check to ensure it is a valid number and handle the case where it is not.

? parseInt(process.env.BA_SERVICE_PRISMA_TIMEOUT, 10)
: 10000,
},
});
}

async onModuleInit() {
await this.$connect();
}
Expand Down