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: allow patching some /credentials sub-paths #4277

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

hperl
Copy link
Contributor

@hperl hperl commented Jan 27, 2025

Related issue(s)

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security vulnerability, I
    confirm that I got the approval (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

We still need to disallow `/credentials/oidc`, because patching this would lead to subtle bugs.
@hperl hperl requested review from aeneasr and a team as code owners January 27, 2025 12:13
@hperl hperl requested a review from aeneasr January 27, 2025 12:13
@hperl hperl self-assigned this Jan 27, 2025
Copy link
Member

@jonas-jonas jonas-jonas left a comment

Choose a reason for hiding this comment

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

Maybe we should also have tests that check, that it's not possible to override nested objects by specifying the wrong path.

E.g.

PATCH 
{
	"op": "replace",
	"path": "/credentials/password",
	"value": {
		"hashed_password": "<hash>"
	},
}

Here, /config/ is missing in the path. Which seems like an easy mistake to make, but would render the identity unusable? Or is this caught by the validator?

identity/handler.go Show resolved Hide resolved
@hperl
Copy link
Contributor Author

hperl commented Jan 27, 2025

Maybe we should also have tests that check, that it's not possible to override nested objects by specifying the wrong path.

E.g.

PATCH 
{
	"op": "replace",
	"path": "/credentials/password",
	"value": {
		"hashed_password": "<hash>"
	},
}

Here, /config/ is missing in the path. Which seems like an easy mistake to make, but would render the identity unusable? Or is this caught by the validator?

Invalid keys are ignored, and AFAIK this is how it has always been.

I agree that this would be useful, and also to extend the PATCHing to OIDC, but here I'd just like to revert to the previous behaviour first (with the added benefit of a test). Let's move this into a new issue?

Copy link

codecov bot commented Jan 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.59%. Comparing base (44eb305) to head (e57e201).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4277      +/-   ##
==========================================
+ Coverage   78.57%   78.59%   +0.01%     
==========================================
  Files         381      381              
  Lines       27376    27376              
==========================================
+ Hits        21511    21516       +5     
+ Misses       4241     4237       -4     
+ Partials     1624     1623       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonas-jonas
Copy link
Member

jonas-jonas commented Jan 27, 2025

Invalid keys are ignored, and AFAIK this is how it has always been.

Not what I meant. The key is technically valid, because the source JSON object the patch is applied against, has the following structure:

{
  "credentials": {
    "password": {
	  "config": {
		"hashed_password": "<hash>",
      }
	}
  }
}

But after applying the faulty patch, the JSON document looks like this:

{
  "credentials": {
    "password": {
	   "hashed_password": "<hash>",
	}
  }
}

Which is not valid, but I am not sure what would happen if you send the request. So a test for that case would be good. Again, I think that is a very common scenario that will happen easily, and we should do our best to prevent it.

alnr
alnr previously requested changes Jan 27, 2025
Copy link
Contributor

@alnr alnr left a comment

Choose a reason for hiding this comment

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

this line of code is still broken and doesn't do what the comment says. pls fix 🙏

patchedIdentity.Credentials = credentials

@aeneasr
Copy link
Member

aeneasr commented Jan 27, 2025

Ideally, for both create, patch, and PUT operations, the following should be implemented with proper
validation:

  1. Passwords:

    • Set or change passwords (with validation ensuring the hash or plaintext password is correct).
    • Delete passwords.
  2. OIDC:

    • Set or change OIDC subject and provider.
    • Delete OIDC subject and provider.
  3. WebAuthn and Passkey Credentials:

    • Set, change, or delete WebAuthn and passkey credentials (e.g., to import passkey users).
  4. Code Credentials:

    • Activate or deactivate code credentials.
  5. TOTP:

    • Set, change, or delete TOTP configurations.
  6. Lookup Secrets:

    • Set, change, or delete lookup secrets.

Restrictions:
What should not be allowed is:

  • Adding arbitrary keys to the config object.
  • Changing identifiers that are typically set by the system.
  • Modifying keys that should only be set by the system.

@hperl hperl dismissed alnr’s stale review January 28, 2025 14:15

I opened #4279 for a proper fix. In the meantime, reverting the forbidden paths is not more wrong / broken than what we currently have, so I'd rather have this merged right now to unblock customers.

@hperl
Copy link
Contributor Author

hperl commented Jan 28, 2025

I opened #4279 for a proper fix. In the meantime, reverting the forbidden paths is not more wrong / broken than what we currently have, so I'd rather have this merged right now to unblock customers.

@hperl hperl merged commit aefa806 into master Jan 28, 2025
27 checks passed
@hperl hperl deleted the hperl/fix-revert-forbid-credentials-subpath branch January 28, 2025 14:15
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.

5 participants