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(services-bff): Move params from ids par requests body to header #16761

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

snaerseljan
Copy link
Contributor

@snaerseljan snaerseljan commented Nov 7, 2024

Move client_id and client_secret from ids par requests body to header

What

This PR moves all client id and secrets from request body to authorization header instead

Why

Client secret was leaking to identity server logs. Duenedes documentation alters from Auth0 2.0 documentation
https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Introduced a new method to generate Basic Authorization headers for Pushed Authorization Requests (PAR).
  • Improvements

    • Streamlined request handling by removing redundant parameters in several methods, enhancing efficiency.
  • Bug Fixes

    • Maintained robust error handling for request responses, ensuring reliability.

@snaerseljan snaerseljan requested a review from a team as a code owner November 7, 2024 14:29
Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes in this pull request focus on the IdsService class within the ids.service.ts file. A new method, createPARAuthorizationHeader, has been introduced to generate a Basic Authorization header for Pushed Authorization Requests (PAR). The postRequest method has been updated to include this header, while the handling of client_id and client_secret has been streamlined across several methods, improving the overall request structure without altering error handling.

Changes

File Path Change Summary
apps/services/bff/src/app/modules/ids/ids.service.ts - Added method createPARAuthorizationHeader() to generate a Basic Authorization header for PAR.
- Updated postRequest to include the new authorization header.
- Simplified getPar, getTokens, refreshToken, and revokeToken methods by removing explicit client_id and client_secret from request body.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • eirikurn

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@snaerseljan snaerseljan added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 7, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
apps/services/bff/src/app/modules/ids/ids.service.ts (1)

126-140: Consider renaming the method to be more generic.

While the implementation is correct, the method name createPARAuthorizationHeader suggests it's specific to PAR (Pushed Authorization Requests). Since this header is used for all OAuth endpoints (tokens, revocation, etc.), consider renaming it to createBasicAuthorizationHeader or createClientAuthorizationHeader.

-  createPARAuthorizationHeader() {
+  createBasicAuthorizationHeader() {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7e8abb4 and b961a3e.

📒 Files selected for processing (1)
  • apps/services/bff/src/app/modules/ids/ids.service.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/services/bff/src/app/modules/ids/ids.service.ts (2)

Pattern apps/services/**/*: "Confirm that the code adheres to the following:

  • NestJS architecture, including modules, services, and controllers.
  • Dependency injection patterns and service encapsulation.
  • Integration and unit testing coverage and practices."

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (3)
apps/services/bff/src/app/modules/ids/ids.service.ts (3)

46-46: LGTM! Authorization header implementation follows OAuth 2.0 spec.

The addition of the Authorization header aligns with RFC 6749 section 2.3.1 and improves security by moving client credentials out of the request body.


46-46: Verify error handling for authentication failures.

While the error handling looks good for general API responses, we should ensure specific handling for authentication failures (HTTP 401/403).

#!/bin/bash
# Search for authentication error handling in tests
echo "Checking for authentication error test coverage..."
rg -A 5 "401|403|unauthorized|forbidden" --type spec

Consider adding specific error handling for authentication failures to provide clear error messages to clients:

if (response.status === 401 || response.status === 403) {
  return {
    type: 'error',
    data: {
      error: 'authentication_failed',
      error_description: 'Invalid client credentials'
    }
  } as ErrorRes;
}

Also applies to: 51-77


151-154: Verify client credentials removal from request bodies.

The implementation correctly moves authentication to headers while maintaining client_id in request parameters. Let's verify that client credentials have been removed from request bodies across the codebase.

✅ Verification successful

Client credentials have been properly removed from request bodies

Based on the comprehensive search results, all postRequest implementations across the codebase have been reviewed and show:

  • In ids.service.ts, client credentials are correctly handled through getLoginSearchParams
  • Other services (documentClient, documentProviderClient) use different authentication mechanisms and don't contain client credentials in request bodies
  • No instances of client_secret being passed directly in request bodies were found
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of client credentials in request bodies
echo "Checking for client_secret in request bodies..."
rg -l "client_secret.*postRequest|postRequest.*client_secret" --type ts

echo "Checking for explicit client_id in request bodies (excluding URL params)..."
rg -l "client_id.*postRequest|postRequest.*client_id" --type ts | \
  grep -v "getLoginSearchParams"

Length of output: 534


Script:

#!/bin/bash
# Search for any remaining instances of client credentials in request bodies
echo "Checking for client_secret in request bodies..."
rg "client_secret.*postRequest|postRequest.*client_secret" --type ts

echo -e "\nChecking for explicit client_id in request bodies..."
rg "client_id.*postRequest|postRequest.*client_id" --type ts

Length of output: 359


Script:

#!/bin/bash
# Let's try a different approach by looking at postRequest usage patterns
echo "Checking postRequest implementations..."
ast-grep --pattern 'postRequest<$_>($$$)'

echo -e "\nChecking getLoginSearchParams usage..."
ast-grep --pattern 'getLoginSearchParams($$$)'

Length of output: 274


Script:

#!/bin/bash
# Search for all TypeScript files containing postRequest method calls
echo "Files containing postRequest calls:"
rg -l "postRequest" --type ts

echo -e "\nDetailed postRequest implementations:"
rg -B2 -A2 "postRequest" --type ts

Length of output: 13872

@kodiakhq kodiakhq bot merged commit 4e05ca2 into main Nov 7, 2024
23 checks passed
@kodiakhq kodiakhq bot deleted the fix/bff-par-requests branch November 7, 2024 15:07
snaerseljan added a commit that referenced this pull request Nov 8, 2024
…16761)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2024
6 tasks
snaerseljan added a commit that referenced this pull request Nov 8, 2024
…16761)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2024
6 tasks
robertaandersen pushed a commit that referenced this pull request Nov 11, 2024
…16761)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
jonnigs pushed a commit that referenced this pull request Nov 12, 2024
…16761)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants