oauth2 2.0.20 → 2.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/IRP.md DELETED
@@ -1,107 +0,0 @@
1
- # Incident Response Plan (IRP)
2
-
3
- Status: Draft
4
-
5
- ## Purpose
6
-
7
- This Incident Response Plan (IRP) defines the steps the project maintainer(s) will follow when handling security incidents related to the `oauth2` gem. It is written for a small project with a single primary maintainer and is intended to be practical, concise, and actionable.
8
-
9
- ## Scope
10
-
11
- Applies to security incidents that affect the `oauth2` codebase, releases (gems), CI/CD infrastructure related to building and publishing the gem, repository credentials, or any compromise of project infrastructure that could impact users.
12
-
13
- ## Key assumptions
14
- - This project is maintained primarily by a single maintainer.
15
- - Public vulnerability disclosure is handled via Tidelift (see `SECURITY.md`).
16
- - The maintainer will act as incident commander unless otherwise delegated.
17
-
18
- ## Contact & Roles
19
-
20
- - Incident Commander: Primary maintainer (repo owner). Responsible for coordinating triage, remediation, and communications.
21
- - Secondary Contact: (optional) A trusted collaborator or organization contact if available.
22
-
23
- ### If you are an external reporter
24
- - Do not publicly disclose details of an active vulnerability before coordination via Tidelift.
25
- - See `SECURITY.md` for Tidelift disclosure instructions. If the reporter has questions and cannot use Tidelift, they may open a direct encrypted report as described in `SECURITY.md` (if available) or email the maintainer contact listed in the repository.
26
-
27
- ## Incident Handling Workflow (high level)
28
- 1. Identification & Reporting
29
- - Reports may arrive via Tidelift, issue tracker, direct email, or third-party advisories.
30
- - Immediately acknowledge receipt (within 24-72 hours) via the reporting channel.
31
-
32
- 2. Triage & Initial Assessment (first 72 hours)
33
- - Confirm the report is not duplicative and gather: reproducer, affected versions, attack surface, exploitability, and CVSS-like severity estimate.
34
- - Verify the issue against the codebase and reproduce locally if possible.
35
- - Determine scope: which versions are affected, whether the issue is in code paths executed in common setups, and whether a workaround exists.
36
-
37
- 3. Containment & Mitigation
38
- - If a simple mitigation or workaround (configuration change, safe default, or recommended upgrade) exists, document it clearly in the issue/Tidelift advisory.
39
- - If immediate removal of a release is required (rare), consult Tidelift for coordinated takedown and notify package hosts if applicable.
40
-
41
- 4. Remediation & Patch
42
- - Prepare a fix in a branch with tests and changelog entries. Prefer minimal, well-tested changes.
43
- - Include tests that reproduce the faulty behavior and demonstrate the fix.
44
- - Hardening: add fuzz tests, input validation, or additional checks as appropriate.
45
-
46
- 5. Release & Disclosure
47
- - Coordinate disclosure through Tidelift per `SECURITY.md` timelines. Aim for a coordinated disclosure and patch release to minimize risk to users.
48
- - Publish a patch release (increment gem version) and an advisory via Tidelift.
49
- - Update `CHANGELOG.md` and repository release notes with non-sensitive details.
50
-
51
- 6. Post-Incident
52
- - Produce a short postmortem: timeline, root cause, actions taken, and follow-ups.
53
- - Add/adjust tests and CI checks to prevent regressions.
54
- - If credentials or infrastructure were compromised, rotate secrets and audit access.
55
-
56
- ## Severity classification (guidance)
57
- - High/Critical: Remote code execution, data exfiltration, or any vulnerability that can be exploited without user interaction. Immediate action and prioritized patching.
58
- - Medium: Privilege escalation, sensitive information leaks that require specific conditions. Patch in the next release cycle with advisory.
59
- - Low: Minor information leaks, UI issues, or non-exploitable bugs. Fix normally and include in the next scheduled release.
60
-
61
- ## Preservation of evidence
62
- - Preserve all reporter-provided data, logs, and reproducer code in a secure location (local encrypted storage or private branch) for the investigation.
63
- - Do not publish evidence that would enable exploitation before coordinated disclosure.
64
-
65
- ## Communication templates
66
- Acknowledgement (to reporter)
67
-
68
- "Thank you for reporting this issue. I've received your report and will triage it within 72 hours. If you can, please provide reproduction steps, affected versions, and any exploit PoC. I will coordinate disclosure through Tidelift per the project's security policy."
69
-
70
- Public advisory (after patch is ready)
71
-
72
- "A security advisory for oauth2 (versions X.Y.Z) has been published via Tidelift. Please upgrade to version A.B.C which patches [brief description]. See the advisory for details and recommended mitigations."
73
-
74
- ## Runbook: Quick steps for a maintainer to patch and release
75
- 1. Create a branch: `git checkout -b fix/security-brief-description`
76
- 2. Reproduce the issue locally and add a regression spec in `spec/`.
77
- 3. Implement the fix and run the test suite: `bundle exec rspec` (or the project's preferred test command).
78
- 4. Bump version in `lib/oauth2/version.rb` following semantic versioning.
79
- 5. Update `CHANGELOG.md` with an entry describing the fix (avoid exploit details).
80
- 6. Commit and push the branch, open a PR, and merge after approvals.
81
- 7. Build and push the gem: `gem build oauth2.gemspec && gem push pkg/...` (coordinate with Tidelift before public push if disclosure is coordinated).
82
- 8. Publish a release on GitHub and ensure the Tidelift advisory is posted.
83
-
84
- ## Operational notes
85
- - Secrets: Use local encrypted storage for any sensitive reporter data. If repository or CI secrets may be compromised, rotate them immediately and update dependent services.
86
- - Access control: Limit who can publish gems and who has admin access to the repo. Keep an up-to-date list of collaborators in a secure place.
87
-
88
- ## Legal & regulatory
89
- - If the incident involves user data or has legal implications, consult legal counsel or the maintainers' employer as appropriate. The maintainer should document the timeline and all communications.
90
-
91
- ## Retrospective & continuous improvement
92
- After an incident, perform a brief post-incident review covering:
93
- - What happened and why
94
- - What was done to contain and remediate
95
- - What tests or process changes will prevent recurrence
96
- - Assign owners and deadlines for follow-up tasks
97
-
98
- ## References
99
- - See `SECURITY.md` for the project's official disclosure channel (Tidelift).
100
-
101
- ## Appendix: Example checklist for an incident
102
- - [ ] Acknowledge report to reporter (24-72 hours)
103
- - [ ] Reproduce and classify severity
104
- - [ ] Prepare and test a fix in a branch
105
- - [ ] Coordinate disclosure via Tidelift
106
- - [ ] Publish patch release and advisory
107
- - [ ] Postmortem and follow-up actions
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2017-2026 Peter H. Boling, of Galtzo.com, and oauth2 contributors
4
- Copyright (c) 2011-2013 Michael Bleigh and Intridea, Inc.
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
data/OIDC.md DELETED
@@ -1,167 +0,0 @@
1
- # OpenID Connect (OIDC) with ruby-oauth/oauth2
2
-
3
- ## OIDC Libraries
4
-
5
- Libraries built on top of the oauth2 gem that implement OIDC.
6
-
7
- - [gamora](https://github.com/amco/gamora-rb) - OpenID Connect Relying Party for Rails apps
8
- - [omniauth-doximity-oauth2](https://github.com/doximity/omniauth-doximity-oauth2) - OmniAuth strategy for Doximity, supporting OIDC, and using PKCE
9
- - [omniauth-himari](https://github.com/sorah/himari) - OmniAuth strategy to act as OIDC RP and use [Himari](https://github.com/sorah/himari) for OP
10
- - [omniauth-mit-oauth2](https://github.com/MITLibraries/omniauth-mit-oauth2) - OmniAuth strategy for MIT OIDC
11
-
12
- If any other libraries would like to be added to this list, please open an issue or pull request.
13
-
14
- ## Raw OIDC with ruby-oauth/oauth2
15
-
16
- This document complements the inline documentation by focusing on OpenID Connect (OIDC) 1.0 usage patterns when using this gem as an OAuth 2.0 client library.
17
-
18
- Scope of this document
19
-
20
- - Audience: Developers building an OAuth 2.0/OIDC Relying Party (RP, aka client) in Ruby.
21
- - Non-goals: This gem does not implement an OIDC Provider (OP, aka Authorization Server); for OP/server see other projects (e.g., doorkeeper + oidc extensions).
22
- - Status: Informational documentation with links to normative specs. The gem intentionally remains protocol-agnostic beyond OAuth 2.0; OIDC specifics (like ID Token validation) must be handled by your application.
23
-
24
- Key concepts refresher
25
-
26
- - OAuth 2.0 delegates authorization; it does not define authentication of the end-user.
27
- - OIDC layers an identity layer on top of OAuth 2.0, introducing:
28
- - ID Token: a JWT carrying claims about the authenticated end-user and the authentication event.
29
- - Standardized scopes: openid (mandatory), profile, email, address, phone, offline_access, and others.
30
- - UserInfo endpoint: a protected resource for retrieving user profile claims.
31
- - Discovery and Dynamic Client Registration (optional for providers/clients that support them).
32
-
33
- What this gem provides for OIDC
34
-
35
- - All OAuth 2.0 client capabilities required for OIDC flows: building authorization requests, exchanging authorization codes, refreshing tokens, and making authenticated resource requests.
36
- - Transport and parsing conveniences (snaky hash, Faraday integration, error handling, etc.).
37
- - Optional client authentication schemes useful with OIDC deployments:
38
- - basic_auth (default)
39
- - request_body (legacy)
40
- - tls_client_auth (MTLS)
41
- - private_key_jwt (OIDC-compliant when configured per OP requirements)
42
-
43
- What you must add in your app for OIDC
44
-
45
- - ID Token validation: This gem surfaces id_token values but does not verify them. Your app should:
46
- 1) Parse the JWT (header, payload, signature)
47
- 2) Fetch the OP JSON Web Key Set (JWKS) from discovery (or configure statically)
48
- 3) Select the correct key by kid (when present) and verify the signature and algorithm
49
- 4) Validate standard claims (iss, aud, exp, iat, nbf, azp, nonce when used, at_hash/c_hash when applicable)
50
- 5) Enforce expected client_id, issuer, and clock skew policies
51
- - Nonce handling for Authorization Code flow with OIDC: generate a cryptographically-random nonce, bind it to the user session before redirect, include it in authorize request, and verify it in the ID Token on return.
52
- - PKCE is best practice and often required by OPs: generate/verifier, send challenge in authorize, send verifier in token request.
53
- - Session/state management: continue to validate state to mitigate CSRF; use exact redirect_uri matching.
54
-
55
- Minimal OIDC Authorization Code example
56
-
57
- ```ruby
58
- require "oauth2"
59
- require "jwt" # jwt/ruby-jwt
60
- require "net/http"
61
- require "json"
62
-
63
- client = OAuth2::Client.new(
64
- ENV.fetch("OIDC_CLIENT_ID"),
65
- ENV.fetch("OIDC_CLIENT_SECRET"),
66
- site: ENV.fetch("OIDC_ISSUER"), # e.g. https://accounts.example.com
67
- authorize_url: "/authorize", # or discovered
68
- token_url: "/token", # or discovered
69
- )
70
-
71
- # Step 1: Redirect to OP for consent/auth
72
- state = SecureRandom.hex(16)
73
- nonce = SecureRandom.hex(16)
74
- pkce_verifier = SecureRandom.urlsafe_base64(64)
75
- pkce_challenge = Base64.urlsafe_encode64(Digest::SHA256.digest(pkce_verifier)).delete("=")
76
-
77
- authz_url = client.auth_code.authorize_url(
78
- scope: "openid profile email",
79
- state: state,
80
- nonce: nonce,
81
- code_challenge: pkce_challenge,
82
- code_challenge_method: "S256",
83
- redirect_uri: ENV.fetch("OIDC_REDIRECT_URI"),
84
- )
85
- # redirect_to authz_url
86
-
87
- # Step 2: Handle callback
88
- # params[:code], params[:state]
89
- raise "state mismatch" unless params[:state] == state
90
-
91
- token = client.auth_code.get_token(
92
- params[:code],
93
- redirect_uri: ENV.fetch("OIDC_REDIRECT_URI"),
94
- code_verifier: pkce_verifier,
95
- )
96
-
97
- # The token may include: access_token, id_token, refresh_token, etc.
98
- id_token = token.params["id_token"] || token.params[:id_token]
99
-
100
- # Step 3: Validate the ID Token (simplified – add your own checks!)
101
- # Discover keys (example using .well-known)
102
- issuer = ENV.fetch("OIDC_ISSUER")
103
- jwks_uri = JSON.parse(Net::HTTP.get(URI.join(issuer, "/.well-known/openid-configuration"))).
104
- fetch("jwks_uri")
105
- jwks = JSON.parse(Net::HTTP.get(URI(jwks_uri)))
106
- keys = jwks.fetch("keys")
107
-
108
- # Use ruby-jwt JWK loader
109
- jwk_set = JWT::JWK::Set.new(keys.map { |k| JWT::JWK.import(k) })
110
-
111
- decoded, headers = JWT.decode(
112
- id_token,
113
- nil,
114
- true,
115
- algorithms: ["RS256", "ES256", "PS256"],
116
- jwks: jwk_set,
117
- verify_iss: true,
118
- iss: issuer,
119
- verify_aud: true,
120
- aud: ENV.fetch("OIDC_CLIENT_ID"),
121
- )
122
-
123
- # Verify nonce
124
- raise "nonce mismatch" unless decoded["nonce"] == nonce
125
-
126
- # Optionally: call UserInfo
127
- userinfo = token.get("/userinfo").parsed
128
- ```
129
-
130
- Notes on discovery and registration
131
-
132
- - Discovery: Most OPs publish configuration at `{issuer}/.well-known/openid-configuration` (OIDC Discovery 1.0). From there, resolve authorization_endpoint, token_endpoint, jwks_uri, userinfo_endpoint, etc.
133
- - Dynamic Client Registration: Some OPs allow registering clients programmatically (OIDC Dynamic Client Registration 1.0). This gem does not implement registration; use a plain HTTP client or Faraday and store credentials securely.
134
-
135
- Common pitfalls and tips
136
-
137
- - Always request the openid scope when you expect an ID Token. Without it, the OP may behave as vanilla OAuth 2.0.
138
- - Validate ID Token signature and claims before trusting any identity data. Do not rely solely on the presence of an id_token field.
139
- - Prefer Authorization Code + PKCE. Avoid Implicit; it is discouraged in modern guidance and may be disabled by providers.
140
- - Use exact redirect_uri matching, and keep your allow-list short.
141
- - For public clients that use refresh tokens, prefer sender-constrained tokens (DPoP/MTLS) or rotation with one-time-use refresh tokens, per modern best practices.
142
- - When using private_key_jwt, ensure the "aud" (or token_url) and "iss/sub" claims are set per the OP’s rules, and include kid in the JWT header when required so the OP can select the right key.
143
-
144
- Relevant specifications and references
145
-
146
- - OpenID Connect Core 1.0: https://openid.net/specs/openid-connect-core-1_0.html
147
- - OIDC Core (final): https://openid.net/specs/openid-connect-core-1_0-final.html
148
- - How OIDC works: https://openid.net/developers/how-connect-works/
149
- - OpenID Connect home: https://openid.net/connect/
150
- - OIDC Discovery 1.0: https://openid.net/specs/openid-connect-discovery-1_0.html
151
- - OIDC Dynamic Client Registration 1.0: https://openid.net/specs/openid-connect-registration-1_0.html
152
- - OIDC Session Management 1.0: https://openid.net/specs/openid-connect-session-1_0.html
153
- - OIDC RP-Initiated Logout 1.0: https://openid.net/specs/openid-connect-rpinitiated-1_0.html
154
- - OIDC Back-Channel Logout 1.0: https://openid.net/specs/openid-connect-backchannel-1_0.html
155
- - OIDC Front-Channel Logout 1.0: https://openid.net/specs/openid-connect-frontchannel-1_0.html
156
- - Auth0 OIDC overview: https://auth0.com/docs/authenticate/protocols/openid-connect-protocol
157
- - Spring Authorization Server’s list of OAuth2/OIDC specs: https://github.com/spring-projects/spring-authorization-server/wiki/OAuth2-and-OIDC-Specifications
158
-
159
- See also
160
-
161
- - README sections on OAuth 2.1 notes and OIDC notes
162
- - Strategy classes under lib/oauth2/strategy for flow helpers
163
- - Specs under spec/oauth2 for concrete usage patterns
164
-
165
- Contributions welcome
166
-
167
- - If you discover provider-specific nuances, consider contributing examples or clarifications (without embedding provider-specific hacks into the library).
data/REEK DELETED
@@ -1,2 +0,0 @@
1
- ./reek: 1: ./reek:: not found
2
- ./reek: 2: ./reek:: not found
data/THREAT_MODEL.md DELETED
@@ -1,94 +0,0 @@
1
- # Threat Model Outline for oauth2 Ruby Gem
2
-
3
- ## 1. Overview
4
- This document outlines the threat model for the `oauth2` Ruby gem, which implements OAuth 2.0, 2.1, and OIDC Core protocols. The gem is used to facilitate secure authorization and authentication in Ruby applications.
5
-
6
- ## 2. Assets to Protect
7
- - OAuth access tokens, refresh tokens, and ID tokens
8
- - User credentials (if handled)
9
- - Client secrets and application credentials
10
- - Sensitive user data accessed via OAuth
11
- - Private keys and certificates (for signing/verifying tokens)
12
-
13
- ## 3. Potential Threat Actors
14
- - External attackers (internet-based)
15
- - Malicious OAuth clients or resource servers
16
- - Insiders (developers, maintainers)
17
- - Compromised dependencies
18
-
19
- ## 4. Attack Surfaces
20
- - OAuth endpoints (authorization, token, revocation, introspection)
21
- - HTTP request/response handling
22
- - Token storage and management
23
- - Configuration files and environment variables
24
- - Dependency supply chain
25
-
26
- ## 5. Threats and Mitigations
27
-
28
- ### 5.1 Token Leakage
29
- - **Threat:** Tokens exposed via logs, URLs, or insecure storage
30
- - **Mitigations:**
31
- - Avoid logging sensitive tokens
32
- - Use secure storage mechanisms
33
- - Never expose tokens in URLs
34
-
35
- ### 5.2 Token Replay and Forgery
36
- - **Threat:** Attackers reuse or forge tokens
37
- - **Mitigations:**
38
- - Validate token signatures and claims
39
- - Use short-lived tokens and refresh tokens
40
- - Implement token revocation
41
-
42
- ### 5.3 Insecure Communication
43
- - **Threat:** Data intercepted via MITM attacks
44
- - **Mitigations:**
45
- - Enforce HTTPS for all communications
46
- - Validate SSL/TLS certificates
47
-
48
- ### 5.4 Client Secret Exposure
49
- - **Threat:** Client secrets leaked in code or version control
50
- - **Mitigations:**
51
- - Store secrets in environment variables or secure vaults
52
- - Never commit secrets to source control
53
-
54
- ### 5.5 Dependency Vulnerabilities
55
- - **Threat:** Vulnerabilities in third-party libraries
56
- - **Mitigations:**
57
- - Regularly update dependencies
58
- - Use tools like `bundler-audit` for vulnerability scanning
59
-
60
- ### 5.6 Improper Input Validation
61
- - **Threat:** Injection attacks via untrusted input
62
- - **Mitigations:**
63
- - Validate and sanitize all inputs
64
- - Use parameterized queries and safe APIs
65
-
66
- ### 5.7 Request-Target Trust Boundary Expansion
67
- - **Threat:** Applications may pass untrusted or insufficiently validated absolute URLs into request paths that can carry OAuth credentials or authenticated state.
68
- - **Risk:** This can expand trust boundaries, contributing to token leakage, authenticated requests to unintended hosts, or SSRF-like pivoting in the surrounding application.
69
- - **Mitigations:**
70
- - Prefer relative paths where practical
71
- - Do not pass untrusted absolute URLs into token-bearing clients
72
- - Validate or allowlist outbound request targets at the application layer
73
- - Treat request-target validation as a separate concern from log redaction and token storage
74
-
75
- ### 5.8 Insufficient Logging and Monitoring
76
- - **Threat:** Attacks go undetected
77
- - **Mitigations:**
78
- - Log security-relevant events (without sensitive data)
79
- - Monitor for suspicious activity
80
-
81
- ## 6. Assumptions
82
- - The gem is used in a secure environment with up-to-date Ruby and dependencies
83
- - End-users are responsible for secure configuration and deployment
84
-
85
- ## 7. Out of Scope
86
- - Security of external OAuth providers
87
- - Application-level business logic
88
-
89
- ## 8. References
90
- - [OAuth 2.0 Threat Model and Security Considerations (RFC 6819)](https://tools.ietf.org/html/rfc6819)
91
- - [OWASP Top Ten](https://owasp.org/www-project-top-ten/)
92
-
93
- ---
94
- This outline should be reviewed and updated regularly as the project evolves.