Skip to content

[GPCAPIM-0000]: POC to access userinfo#91

Open
davidhamill1-nhs wants to merge 3 commits intomainfrom
feature/GPCAPIM-0000_userinfo_testing
Open

[GPCAPIM-0000]: POC to access userinfo#91
davidhamill1-nhs wants to merge 3 commits intomainfrom
feature/GPCAPIM-0000_userinfo_testing

Conversation

@davidhamill1-nhs
Copy link
Copy Markdown
Contributor

…) to the backend, enabling us to understand who is calling us and pass that on to the GP provider system

Description

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming
  • Exceptions/Exclusions to coding standards (e.g. #noqa or #NOSONAR) are included within this Pull Request.

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

@davidhamill1-nhs davidhamill1-nhs requested a review from a team as a code owner February 25, 2026 16:11
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 25, 2026

Trivy gate: no Critical/High issues.

Trivy IaC (Terraform) Summary

Severity Count
CRITICAL 0
HIGH 0
MEDIUM 0
LOW 0
UNKNOWN 0
Findings (top 50)
Severity ID Title File

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 25, 2026

Trivy gate: no Critical/High vulnerabilities.

Trivy Image Scan Summary

Image: 900119715266.dkr.ecr.eu-west-2.amazonaws.com/whoami:feature-gpcapim-0000-userinfo-testing

Severity Count
CRITICAL 0
HIGH 0
MEDIUM 0
LOW 1
UNKNOWN 0
Findings (top 50)
Severity ID Package Installed Fixed Source
LOW CVE-2026-1703 pip 25.3 26.0 Python

@davidhamill1-nhs davidhamill1-nhs force-pushed the feature/GPCAPIM-0000_userinfo_testing branch from 62e3b39 to 2be9923 Compare March 4, 2026 11:27
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2026

Deployment Complete

@DWolfsNHS DWolfsNHS force-pushed the feature/GPCAPIM-0000_userinfo_testing branch from 2be9923 to 4fdb19f Compare March 23, 2026 10:25
Copilot AI review requested due to automatic review settings March 23, 2026 10:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds initial plumbing to surface caller identity information to the backend, as a POC toward accessing CIS2 userinfo and passing identity context through the proxy.

Changes:

  • Configures Proxygen/APIM template to forward CIS2-related identity fields (including id-token) to the target.
  • Adds request header logging to the /patient/$gpc.getstructuredrecord Flask handler for debugging.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
proxygen/x-nhsd-apim.template.yaml Adds target-identity entries to forward CIS2 identity data (and id-token) to the backend.
gateway-api/src/gateway_api/app.py Logs incoming request headers for the structured record endpoint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@app.route("/patient/$gpc.getstructuredrecord", methods=["POST"])
def get_structured_record() -> Response:
try:
print(f"Headers: {request.headers}", flush=True)
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Printing the full incoming request headers will likely log sensitive values (e.g., Authorization, id_token, correlation IDs) into application logs, which is a security/privacy risk and can violate the repo’s “no PII/sensitive data” requirement. Please remove this, or replace with allowlisted/redacted logging (e.g., only safe headers, explicitly redact auth/token headers) and ensure it’s gated behind a debug/non-prod flag if needed for the POC.

Suggested change
print(f"Headers: {request.headers}", flush=True)
debug_log_headers = os.getenv("DEBUG_LOG_HEADERS", "false").lower() == "true"
if debug_log_headers:
# Only log a limited set of non-sensitive headers for debugging purposes.
safe_header_names = {"Content-Type", "Accept", "User-Agent"}
safe_headers = {
name: value
for name, value in request.headers.items()
if name in safe_header_names
}
print(f"Safe headers: {safe_headers}", flush=True)

Copilot uses AI. Check for mistakes.
- name: cis2-uuid
- name: cis2-urid
- name: cis2-acr
- name: id-token
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Forwarding id-token via target-identity increases the risk of propagating a sensitive bearer token to downstream services and into logs/telemetry. If the backend only needs specific user identifiers, prefer passing just those minimal claims (e.g., cis2-uuid/urid/acr) and avoid forwarding the full token unless there’s a clear, documented requirement.

Suggested change
- name: id-token

Copilot uses AI. Check for mistakes.
Comment on lines +14 to +18
target-identity:
- name: cis2-uuid
- name: cis2-urid
- name: cis2-acr
- name: id-token
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

target-identity is being added to the Proxygen x-nhsd-apim template, but proxygen/README.md currently lists what the extension includes and doesn’t mention this new field. Please update the documentation accordingly so future maintainers know why these identity headers are configured and what each one is used for.

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link
Copy Markdown

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.

2 participants