Compare commits
15 Commits
5137a25626
...
0.8.6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e631f606e7 | ||
|
|
f4a697ae9b | ||
|
|
16e34ffaf0 | ||
|
|
0bb84f08d6 | ||
|
|
182682024d | ||
|
|
b517ebe809 | ||
|
|
dd8bd15a76 | ||
|
|
f67a73821c | ||
|
|
b09ddf6db5 | ||
|
|
abbb11a41d | ||
|
|
b2030df8c2 | ||
|
|
07cddf5823 | ||
|
|
46aa983189 | ||
|
|
d0d79ee1da | ||
|
|
2f6a2c7406 |
28
.github/workflows/ci.yml
vendored
28
.github/workflows/ci.yml
vendored
@@ -41,6 +41,34 @@ jobs:
|
|||||||
- name: Scan for security vulnerabilities in JavaScript dependencies
|
- name: Scan for security vulnerabilities in JavaScript dependencies
|
||||||
run: bin/importmap audit
|
run: bin/importmap audit
|
||||||
|
|
||||||
|
scan_container:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
security-events: write # Required for uploading SARIF results
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: Build Docker image
|
||||||
|
run: docker build -t clinch:${{ github.sha }} .
|
||||||
|
|
||||||
|
- name: Run Trivy vulnerability scanner
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
image-ref: clinch:${{ github.sha }}
|
||||||
|
format: 'sarif'
|
||||||
|
output: 'trivy-results.sarif'
|
||||||
|
severity: 'CRITICAL,HIGH'
|
||||||
|
scanners: 'vuln' # Only scan vulnerabilities, not secrets (avoids false positives in vendored gems)
|
||||||
|
|
||||||
|
- name: Upload Trivy results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v3
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
sarif_file: 'trivy-results.sarif'
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
3.4.6
|
3.4.8
|
||||||
|
|||||||
48
.trivyignore
Normal file
48
.trivyignore
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Trivy ignore file
|
||||||
|
# This file tells Trivy to skip specific vulnerabilities or files
|
||||||
|
# See: https://aquasecurity.github.io/trivy/latest/docs/configuration/filtering/
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# False Positives - Test Fixtures
|
||||||
|
# =============================================================================
|
||||||
|
|
||||||
|
# Capybara test fixture - not a real private key
|
||||||
|
# Ignore secrets in test fixtures
|
||||||
|
# Format: secret:<rule-id>:<exact-file-path>
|
||||||
|
secret:private-key:/usr/local/bundle/ruby/3.4.0/gems/capybara-3.40.0/spec/fixtures/key.pem
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Unfixable CVEs - No Patches Available (Status: affected/fix_deferred)
|
||||||
|
# =============================================================================
|
||||||
|
|
||||||
|
# GnuPG vulnerabilities - not used by Clinch at runtime
|
||||||
|
# Low risk: dirmngr/gpg tools not invoked during normal operation
|
||||||
|
CVE-2025-68973
|
||||||
|
|
||||||
|
# Image processing library vulnerabilities
|
||||||
|
# Low risk for Clinch: Only admins upload images (app icons), not untrusted users
|
||||||
|
# Waiting on Debian security team to release patches
|
||||||
|
|
||||||
|
# ImageMagick - Integer overflow (32-bit only)
|
||||||
|
CVE-2025-66628
|
||||||
|
|
||||||
|
# glib - Integer overflow in URI escaping
|
||||||
|
CVE-2025-13601
|
||||||
|
|
||||||
|
# HDF5 - Critical vulnerabilities in scientific data format library
|
||||||
|
CVE-2025-2153
|
||||||
|
CVE-2025-2308
|
||||||
|
CVE-2025-2309
|
||||||
|
CVE-2025-2310
|
||||||
|
|
||||||
|
# libmatio - MATLAB file format library
|
||||||
|
CVE-2025-2338
|
||||||
|
|
||||||
|
# OpenEXR - Image format vulnerabilities
|
||||||
|
CVE-2025-12495
|
||||||
|
CVE-2025-12839
|
||||||
|
CVE-2025-12840
|
||||||
|
CVE-2025-64181
|
||||||
|
|
||||||
|
# libvips - Image processing library
|
||||||
|
CVE-2025-59933
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
|
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
|
||||||
|
|
||||||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
|
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
|
||||||
ARG RUBY_VERSION=3.4.6
|
ARG RUBY_VERSION=3.4.8
|
||||||
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
|
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source=https://github.com/dkam/clinch
|
LABEL org.opencontainers.image.source=https://github.com/dkam/clinch
|
||||||
@@ -16,8 +16,9 @@ LABEL org.opencontainers.image.source=https://github.com/dkam/clinch
|
|||||||
# Rails app lives here
|
# Rails app lives here
|
||||||
WORKDIR /rails
|
WORKDIR /rails
|
||||||
|
|
||||||
# Install base packages
|
# Install base packages and upgrade to latest security patches
|
||||||
RUN apt-get update -qq && \
|
RUN apt-get update -qq && \
|
||||||
|
apt-get upgrade -y && \
|
||||||
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
|
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
|
||||||
ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so && \
|
ln -s /usr/lib/$(uname -m)-linux-gnu/libjemalloc.so.2 /usr/local/lib/libjemalloc.so && \
|
||||||
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
rm -rf /var/lib/apt/lists /var/cache/apt/archives
|
||||||
|
|||||||
3
Gemfile
3
Gemfile
@@ -90,4 +90,7 @@ group :test do
|
|||||||
|
|
||||||
# Code coverage analysis
|
# Code coverage analysis
|
||||||
gem "simplecov", require: false
|
gem "simplecov", require: false
|
||||||
|
|
||||||
|
# Pin minitest to < 6.0 until Rails 8.1 supports the new API
|
||||||
|
gem "minitest", "< 6.0"
|
||||||
end
|
end
|
||||||
|
|||||||
131
Gemfile.lock
131
Gemfile.lock
@@ -1,7 +1,7 @@
|
|||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
action_text-trix (2.1.15)
|
action_text-trix (2.1.16)
|
||||||
railties
|
railties
|
||||||
actioncable (8.1.1)
|
actioncable (8.1.1)
|
||||||
actionpack (= 8.1.1)
|
actionpack (= 8.1.1)
|
||||||
@@ -80,14 +80,14 @@ GEM
|
|||||||
android_key_attestation (0.3.0)
|
android_key_attestation (0.3.0)
|
||||||
ast (2.4.3)
|
ast (2.4.3)
|
||||||
base64 (0.3.0)
|
base64 (0.3.0)
|
||||||
bcrypt (3.1.20)
|
bcrypt (3.1.21)
|
||||||
bcrypt_pbkdf (1.1.1)
|
bcrypt_pbkdf (1.1.2)
|
||||||
bigdecimal (3.3.1)
|
bigdecimal (4.0.1)
|
||||||
bindata (2.5.1)
|
bindata (2.5.1)
|
||||||
bindex (0.8.1)
|
bindex (0.8.1)
|
||||||
bootsnap (1.19.0)
|
bootsnap (1.20.1)
|
||||||
msgpack (~> 1.2)
|
msgpack (~> 1.2)
|
||||||
brakeman (7.1.1)
|
brakeman (7.1.2)
|
||||||
racc
|
racc
|
||||||
builder (3.3.0)
|
builder (3.3.0)
|
||||||
bundler-audit (0.9.3)
|
bundler-audit (0.9.3)
|
||||||
@@ -106,37 +106,37 @@ GEM
|
|||||||
childprocess (5.1.0)
|
childprocess (5.1.0)
|
||||||
logger (~> 1.5)
|
logger (~> 1.5)
|
||||||
chunky_png (1.4.0)
|
chunky_png (1.4.0)
|
||||||
concurrent-ruby (1.3.5)
|
concurrent-ruby (1.3.6)
|
||||||
connection_pool (2.5.5)
|
connection_pool (3.0.2)
|
||||||
cose (1.3.1)
|
cose (1.3.1)
|
||||||
cbor (~> 0.5.9)
|
cbor (~> 0.5.9)
|
||||||
openssl-signature_algorithm (~> 1.0)
|
openssl-signature_algorithm (~> 1.0)
|
||||||
crass (1.0.6)
|
crass (1.0.6)
|
||||||
date (3.5.0)
|
date (3.5.1)
|
||||||
debug (1.11.0)
|
debug (1.11.1)
|
||||||
irb (~> 1.10)
|
irb (~> 1.10)
|
||||||
reline (>= 0.3.8)
|
reline (>= 0.3.8)
|
||||||
docile (1.4.1)
|
docile (1.4.1)
|
||||||
dotenv (3.1.8)
|
dotenv (3.2.0)
|
||||||
drb (2.2.3)
|
drb (2.2.3)
|
||||||
ed25519 (1.4.0)
|
ed25519 (1.4.0)
|
||||||
erb (6.0.0)
|
erb (6.0.1)
|
||||||
erubi (1.13.1)
|
erubi (1.13.1)
|
||||||
et-orbi (1.4.0)
|
et-orbi (1.4.0)
|
||||||
tzinfo
|
tzinfo
|
||||||
ffi (1.17.2-aarch64-linux-gnu)
|
ffi (1.17.3-aarch64-linux-gnu)
|
||||||
ffi (1.17.2-aarch64-linux-musl)
|
ffi (1.17.3-aarch64-linux-musl)
|
||||||
ffi (1.17.2-arm-linux-gnu)
|
ffi (1.17.3-arm-linux-gnu)
|
||||||
ffi (1.17.2-arm-linux-musl)
|
ffi (1.17.3-arm-linux-musl)
|
||||||
ffi (1.17.2-arm64-darwin)
|
ffi (1.17.3-arm64-darwin)
|
||||||
ffi (1.17.2-x86_64-linux-gnu)
|
ffi (1.17.3-x86_64-linux-gnu)
|
||||||
ffi (1.17.2-x86_64-linux-musl)
|
ffi (1.17.3-x86_64-linux-musl)
|
||||||
fugit (1.12.1)
|
fugit (1.12.1)
|
||||||
et-orbi (~> 1.4)
|
et-orbi (~> 1.4)
|
||||||
raabro (~> 1.4)
|
raabro (~> 1.4)
|
||||||
globalid (1.3.0)
|
globalid (1.3.0)
|
||||||
activesupport (>= 6.1)
|
activesupport (>= 6.1)
|
||||||
i18n (1.14.7)
|
i18n (1.14.8)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
image_processing (1.14.0)
|
image_processing (1.14.0)
|
||||||
mini_magick (>= 4.9.5, < 6)
|
mini_magick (>= 4.9.5, < 6)
|
||||||
@@ -145,18 +145,18 @@ GEM
|
|||||||
actionpack (>= 6.0.0)
|
actionpack (>= 6.0.0)
|
||||||
activesupport (>= 6.0.0)
|
activesupport (>= 6.0.0)
|
||||||
railties (>= 6.0.0)
|
railties (>= 6.0.0)
|
||||||
io-console (0.8.1)
|
io-console (0.8.2)
|
||||||
irb (1.15.3)
|
irb (1.16.0)
|
||||||
pp (>= 0.6.0)
|
pp (>= 0.6.0)
|
||||||
rdoc (>= 4.0.0)
|
rdoc (>= 4.0.0)
|
||||||
reline (>= 0.4.2)
|
reline (>= 0.4.2)
|
||||||
jbuilder (2.14.1)
|
jbuilder (2.14.1)
|
||||||
actionview (>= 7.0.0)
|
actionview (>= 7.0.0)
|
||||||
activesupport (>= 7.0.0)
|
activesupport (>= 7.0.0)
|
||||||
json (2.16.0)
|
json (2.18.0)
|
||||||
jwt (3.1.2)
|
jwt (3.1.2)
|
||||||
base64
|
base64
|
||||||
kamal (2.9.0)
|
kamal (2.10.1)
|
||||||
activesupport (>= 7.0)
|
activesupport (>= 7.0)
|
||||||
base64 (~> 0.2)
|
base64 (~> 0.2)
|
||||||
bcrypt_pbkdf (~> 1.0)
|
bcrypt_pbkdf (~> 1.0)
|
||||||
@@ -176,7 +176,7 @@ GEM
|
|||||||
launchy (>= 2.2, < 4)
|
launchy (>= 2.2, < 4)
|
||||||
lint_roller (1.1.0)
|
lint_roller (1.1.0)
|
||||||
logger (1.7.0)
|
logger (1.7.0)
|
||||||
loofah (2.24.1)
|
loofah (2.25.0)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.12.0)
|
nokogiri (>= 1.12.0)
|
||||||
mail (2.9.0)
|
mail (2.9.0)
|
||||||
@@ -190,9 +190,9 @@ GEM
|
|||||||
mini_magick (5.3.1)
|
mini_magick (5.3.1)
|
||||||
logger
|
logger
|
||||||
mini_mime (1.1.5)
|
mini_mime (1.1.5)
|
||||||
minitest (5.26.2)
|
minitest (5.27.0)
|
||||||
msgpack (1.8.0)
|
msgpack (1.8.0)
|
||||||
net-imap (0.5.12)
|
net-imap (0.6.2)
|
||||||
date
|
date
|
||||||
net-protocol
|
net-protocol
|
||||||
net-pop (0.1.2)
|
net-pop (0.1.2)
|
||||||
@@ -207,21 +207,21 @@ GEM
|
|||||||
net-protocol
|
net-protocol
|
||||||
net-ssh (7.3.0)
|
net-ssh (7.3.0)
|
||||||
nio4r (2.7.5)
|
nio4r (2.7.5)
|
||||||
nokogiri (1.18.10-aarch64-linux-gnu)
|
nokogiri (1.19.0-aarch64-linux-gnu)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.18.10-aarch64-linux-musl)
|
nokogiri (1.19.0-aarch64-linux-musl)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.18.10-arm-linux-gnu)
|
nokogiri (1.19.0-arm-linux-gnu)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.18.10-arm-linux-musl)
|
nokogiri (1.19.0-arm-linux-musl)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.18.10-arm64-darwin)
|
nokogiri (1.19.0-arm64-darwin)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.18.10-x86_64-linux-gnu)
|
nokogiri (1.19.0-x86_64-linux-gnu)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
nokogiri (1.18.10-x86_64-linux-musl)
|
nokogiri (1.19.0-x86_64-linux-musl)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
openssl (3.3.2)
|
openssl (4.0.0)
|
||||||
openssl-signature_algorithm (1.3.0)
|
openssl-signature_algorithm (1.3.0)
|
||||||
openssl (> 2.0)
|
openssl (> 2.0)
|
||||||
ostruct (0.6.3)
|
ostruct (0.6.3)
|
||||||
@@ -232,12 +232,12 @@ GEM
|
|||||||
pp (0.6.3)
|
pp (0.6.3)
|
||||||
prettyprint
|
prettyprint
|
||||||
prettyprint (0.2.0)
|
prettyprint (0.2.0)
|
||||||
prism (1.6.0)
|
prism (1.7.0)
|
||||||
propshaft (1.3.1)
|
propshaft (1.3.1)
|
||||||
actionpack (>= 7.0.0)
|
actionpack (>= 7.0.0)
|
||||||
activesupport (>= 7.0.0)
|
activesupport (>= 7.0.0)
|
||||||
rack
|
rack
|
||||||
psych (5.2.6)
|
psych (5.3.1)
|
||||||
date
|
date
|
||||||
stringio
|
stringio
|
||||||
public_suffix (7.0.0)
|
public_suffix (7.0.0)
|
||||||
@@ -251,7 +251,7 @@ GEM
|
|||||||
rack (>= 3.0.0)
|
rack (>= 3.0.0)
|
||||||
rack-test (2.2.0)
|
rack-test (2.2.0)
|
||||||
rack (>= 1.3)
|
rack (>= 1.3)
|
||||||
rackup (2.2.1)
|
rackup (2.3.1)
|
||||||
rack (>= 3)
|
rack (>= 3)
|
||||||
rails (8.1.1)
|
rails (8.1.1)
|
||||||
actioncable (= 8.1.1)
|
actioncable (= 8.1.1)
|
||||||
@@ -285,7 +285,7 @@ GEM
|
|||||||
zeitwerk (~> 2.6)
|
zeitwerk (~> 2.6)
|
||||||
rainbow (3.1.1)
|
rainbow (3.1.1)
|
||||||
rake (13.3.1)
|
rake (13.3.1)
|
||||||
rdoc (6.16.1)
|
rdoc (7.0.3)
|
||||||
erb
|
erb
|
||||||
psych (>= 4.0.0)
|
psych (>= 4.0.0)
|
||||||
tsort
|
tsort
|
||||||
@@ -309,22 +309,22 @@ GEM
|
|||||||
rubocop-ast (>= 1.47.1, < 2.0)
|
rubocop-ast (>= 1.47.1, < 2.0)
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
unicode-display_width (>= 2.4.0, < 4.0)
|
unicode-display_width (>= 2.4.0, < 4.0)
|
||||||
rubocop-ast (1.48.0)
|
rubocop-ast (1.49.0)
|
||||||
parser (>= 3.3.7.2)
|
parser (>= 3.3.7.2)
|
||||||
prism (~> 1.4)
|
prism (~> 1.7)
|
||||||
rubocop-performance (1.26.1)
|
rubocop-performance (1.26.1)
|
||||||
lint_roller (~> 1.1)
|
lint_roller (~> 1.1)
|
||||||
rubocop (>= 1.75.0, < 2.0)
|
rubocop (>= 1.75.0, < 2.0)
|
||||||
rubocop-ast (>= 1.47.1, < 2.0)
|
rubocop-ast (>= 1.47.1, < 2.0)
|
||||||
ruby-progressbar (1.13.0)
|
ruby-progressbar (1.13.0)
|
||||||
ruby-vips (2.2.5)
|
ruby-vips (2.3.0)
|
||||||
ffi (~> 1.12)
|
ffi (~> 1.12)
|
||||||
logger
|
logger
|
||||||
rubyzip (3.2.2)
|
rubyzip (3.2.2)
|
||||||
safety_net_attestation (0.5.0)
|
safety_net_attestation (0.5.0)
|
||||||
jwt (>= 2.0, < 4.0)
|
jwt (>= 2.0, < 4.0)
|
||||||
securerandom (0.4.1)
|
securerandom (0.4.1)
|
||||||
selenium-webdriver (4.38.0)
|
selenium-webdriver (4.39.0)
|
||||||
base64 (~> 0.2)
|
base64 (~> 0.2)
|
||||||
logger (~> 1.4)
|
logger (~> 1.4)
|
||||||
rexml (~> 3.2, >= 3.2.5)
|
rexml (~> 3.2, >= 3.2.5)
|
||||||
@@ -358,14 +358,14 @@ GEM
|
|||||||
fugit (~> 1.11)
|
fugit (~> 1.11)
|
||||||
railties (>= 7.1)
|
railties (>= 7.1)
|
||||||
thor (>= 1.3.1)
|
thor (>= 1.3.1)
|
||||||
sqlite3 (2.8.1-aarch64-linux-gnu)
|
sqlite3 (2.9.0-aarch64-linux-gnu)
|
||||||
sqlite3 (2.8.1-aarch64-linux-musl)
|
sqlite3 (2.9.0-aarch64-linux-musl)
|
||||||
sqlite3 (2.8.1-arm-linux-gnu)
|
sqlite3 (2.9.0-arm-linux-gnu)
|
||||||
sqlite3 (2.8.1-arm-linux-musl)
|
sqlite3 (2.9.0-arm-linux-musl)
|
||||||
sqlite3 (2.8.1-arm64-darwin)
|
sqlite3 (2.9.0-arm64-darwin)
|
||||||
sqlite3 (2.8.1-x86_64-linux-gnu)
|
sqlite3 (2.9.0-x86_64-linux-gnu)
|
||||||
sqlite3 (2.8.1-x86_64-linux-musl)
|
sqlite3 (2.9.0-x86_64-linux-musl)
|
||||||
sshkit (1.24.0)
|
sshkit (1.25.0)
|
||||||
base64
|
base64
|
||||||
logger
|
logger
|
||||||
net-scp (>= 1.1.2)
|
net-scp (>= 1.1.2)
|
||||||
@@ -386,22 +386,22 @@ GEM
|
|||||||
rubocop-performance (~> 1.26.0)
|
rubocop-performance (~> 1.26.0)
|
||||||
stimulus-rails (1.3.4)
|
stimulus-rails (1.3.4)
|
||||||
railties (>= 6.0.0)
|
railties (>= 6.0.0)
|
||||||
stringio (3.1.8)
|
stringio (3.2.0)
|
||||||
tailwindcss-rails (4.4.0)
|
tailwindcss-rails (4.4.0)
|
||||||
railties (>= 7.0.0)
|
railties (>= 7.0.0)
|
||||||
tailwindcss-ruby (~> 4.0)
|
tailwindcss-ruby (~> 4.0)
|
||||||
tailwindcss-ruby (4.1.16)
|
tailwindcss-ruby (4.1.18)
|
||||||
tailwindcss-ruby (4.1.16-aarch64-linux-gnu)
|
tailwindcss-ruby (4.1.18-aarch64-linux-gnu)
|
||||||
tailwindcss-ruby (4.1.16-aarch64-linux-musl)
|
tailwindcss-ruby (4.1.18-aarch64-linux-musl)
|
||||||
tailwindcss-ruby (4.1.16-arm64-darwin)
|
tailwindcss-ruby (4.1.18-arm64-darwin)
|
||||||
tailwindcss-ruby (4.1.16-x86_64-linux-gnu)
|
tailwindcss-ruby (4.1.18-x86_64-linux-gnu)
|
||||||
tailwindcss-ruby (4.1.16-x86_64-linux-musl)
|
tailwindcss-ruby (4.1.18-x86_64-linux-musl)
|
||||||
thor (1.4.0)
|
thor (1.4.0)
|
||||||
thruster (0.1.16)
|
thruster (0.1.17)
|
||||||
thruster (0.1.16-aarch64-linux)
|
thruster (0.1.17-aarch64-linux)
|
||||||
thruster (0.1.16-arm64-darwin)
|
thruster (0.1.17-arm64-darwin)
|
||||||
thruster (0.1.16-x86_64-linux)
|
thruster (0.1.17-x86_64-linux)
|
||||||
timeout (0.4.4)
|
timeout (0.6.0)
|
||||||
tpm-key_attestation (0.14.1)
|
tpm-key_attestation (0.14.1)
|
||||||
bindata (~> 2.4)
|
bindata (~> 2.4)
|
||||||
openssl (> 2.0)
|
openssl (> 2.0)
|
||||||
@@ -437,7 +437,7 @@ GEM
|
|||||||
websocket-extensions (0.1.5)
|
websocket-extensions (0.1.5)
|
||||||
xpath (3.2.0)
|
xpath (3.2.0)
|
||||||
nokogiri (~> 1.8)
|
nokogiri (~> 1.8)
|
||||||
zeitwerk (2.7.3)
|
zeitwerk (2.7.4)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
aarch64-linux
|
aarch64-linux
|
||||||
@@ -463,6 +463,7 @@ DEPENDENCIES
|
|||||||
jwt (~> 3.1)
|
jwt (~> 3.1)
|
||||||
kamal
|
kamal
|
||||||
letter_opener
|
letter_opener
|
||||||
|
minitest (< 6.0)
|
||||||
propshaft
|
propshaft
|
||||||
public_suffix (~> 7.0)
|
public_suffix (~> 7.0)
|
||||||
puma (>= 5.0)
|
puma (>= 5.0)
|
||||||
@@ -487,4 +488,4 @@ DEPENDENCIES
|
|||||||
webauthn (~> 3.0)
|
webauthn (~> 3.0)
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.7.2
|
4.0.3
|
||||||
|
|||||||
52
README.md
52
README.md
@@ -1,8 +1,10 @@
|
|||||||
# Clinch
|
# Clinch
|
||||||
|
## Position and Control for your Authentication
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> This software is experimental. If you'd like to try it out, find bugs, security flaws and improvements, please do.
|
> This software is experimental. If you'd like to try it out, find bugs, security flaws and improvements, please do.
|
||||||
|
|
||||||
|
We do these things not because they're easy, but because we thought they'd be easy.
|
||||||
|
|
||||||
**A lightweight, self-hosted identity & SSO / IpD portal**
|
**A lightweight, self-hosted identity & SSO / IpD portal**
|
||||||
|
|
||||||
Clinch gives you one place to manage users and lets any web app authenticate against it without managing its own users.
|
Clinch gives you one place to manage users and lets any web app authenticate against it without managing its own users.
|
||||||
@@ -347,27 +349,39 @@ services:
|
|||||||
|
|
||||||
Create a `.env` file in the same directory:
|
Create a `.env` file in the same directory:
|
||||||
|
|
||||||
```bash
|
**Generate required secrets first:**
|
||||||
# Generate with: openssl rand -hex 64
|
|
||||||
SECRET_KEY_BASE=your-secret-key-here
|
|
||||||
|
|
||||||
# Application URLs
|
```bash
|
||||||
|
# Generate SECRET_KEY_BASE (required)
|
||||||
|
openssl rand -hex 64
|
||||||
|
|
||||||
|
# Generate OIDC private key (optional - auto-generated if not provided)
|
||||||
|
openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
|
||||||
|
cat private_key.pem # Copy the output into OIDC_PRIVATE_KEY below
|
||||||
|
```
|
||||||
|
|
||||||
|
**Then create `.env`:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Rails Secret (REQUIRED)
|
||||||
|
SECRET_KEY_BASE=paste-output-from-openssl-rand-hex-64-here
|
||||||
|
|
||||||
|
# Application URLs (REQUIRED)
|
||||||
CLINCH_HOST=https://auth.yourdomain.com
|
CLINCH_HOST=https://auth.yourdomain.com
|
||||||
CLINCH_FROM_EMAIL=noreply@yourdomain.com
|
CLINCH_FROM_EMAIL=noreply@yourdomain.com
|
||||||
|
|
||||||
# SMTP Settings
|
# SMTP Settings (REQUIRED for invitations and password resets)
|
||||||
SMTP_ADDRESS=smtp.example.com
|
SMTP_ADDRESS=smtp.example.com
|
||||||
SMTP_PORT=587
|
SMTP_PORT=587
|
||||||
SMTP_DOMAIN=yourdomain.com
|
SMTP_DOMAIN=yourdomain.com
|
||||||
SMTP_USERNAME=your-smtp-username
|
SMTP_USERNAME=your-smtp-username
|
||||||
SMTP_PASSWORD=your-smtp-password
|
SMTP_PASSWORD=your-smtp-password
|
||||||
|
|
||||||
# OIDC (optional - generates temporary key if not set)
|
# OIDC Private Key (OPTIONAL - generates temporary key if not provided)
|
||||||
# Generate with: openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
|
# For production, generate a persistent key and paste the ENTIRE contents here
|
||||||
# Then: OIDC_PRIVATE_KEY=$(cat private_key.pem)
|
|
||||||
OIDC_PRIVATE_KEY=
|
OIDC_PRIVATE_KEY=
|
||||||
|
|
||||||
# Optional: Force SSL redirects (if not behind a reverse proxy handling SSL)
|
# Optional: Force SSL redirects (only if NOT behind a reverse proxy handling SSL)
|
||||||
FORCE_SSL=false
|
FORCE_SSL=false
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -715,12 +729,30 @@ bin/bundler-audit check --update # Dependency vulnerability scan
|
|||||||
bin/importmap audit # JavaScript dependency scan
|
bin/importmap audit # JavaScript dependency scan
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Container Image Scanning:**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install Trivy
|
||||||
|
brew install trivy # macOS
|
||||||
|
# or use Docker: alias trivy='docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy'
|
||||||
|
|
||||||
|
# Build and scan image (CRITICAL and HIGH severity only, like CI)
|
||||||
|
docker build -t clinch:local .
|
||||||
|
trivy image --severity CRITICAL,HIGH --scanners vuln clinch:local
|
||||||
|
|
||||||
|
# Scan only for fixable vulnerabilities
|
||||||
|
trivy image --severity CRITICAL,HIGH --scanners vuln --ignore-unfixed clinch:local
|
||||||
|
```
|
||||||
|
|
||||||
**CI/CD Integration:**
|
**CI/CD Integration:**
|
||||||
All security scans run automatically on every pull request and push to main via GitHub Actions.
|
All security scans run automatically on every pull request and push to main via GitHub Actions.
|
||||||
|
|
||||||
**Security Tools:**
|
**Security Tools:**
|
||||||
- **Brakeman** - Static analysis for Rails security vulnerabilities
|
- **Brakeman** - Static analysis for Rails security vulnerabilities
|
||||||
- **bundler-audit** - Checks gems for known CVEs
|
- **bundler-audit** - Checks gems for known CVEs
|
||||||
|
- **Trivy** - Container image vulnerability scanning (OS/system packages)
|
||||||
|
- **Dependabot** - Automated dependency updates
|
||||||
|
- **GitHub Secret Scanning** - Detects leaked credentials with push protection
|
||||||
- **SimpleCov** - Code coverage tracking
|
- **SimpleCov** - Code coverage tracking
|
||||||
- **RuboCop** - Code style and quality enforcement
|
- **RuboCop** - Code style and quality enforcement
|
||||||
|
|
||||||
|
|||||||
@@ -52,12 +52,24 @@ module Authentication
|
|||||||
# Extract root domain for cross-subdomain cookies (required for forward auth)
|
# Extract root domain for cross-subdomain cookies (required for forward auth)
|
||||||
domain = extract_root_domain(request.host)
|
domain = extract_root_domain(request.host)
|
||||||
|
|
||||||
cookie_options = {
|
# Set cookie options based on environment
|
||||||
value: session.id,
|
# Production: Use SameSite=None to allow cross-site cookies (needed for OIDC conformance testing)
|
||||||
httponly: true,
|
# Development: Use SameSite=Lax since HTTPS might not be available
|
||||||
same_site: :lax,
|
cookie_options = if Rails.env.production?
|
||||||
secure: Rails.env.production?
|
{
|
||||||
}
|
value: session.id,
|
||||||
|
httponly: true,
|
||||||
|
same_site: :none, # Allow cross-site cookies for OIDC testing
|
||||||
|
secure: true # Required for SameSite=None
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value: session.id,
|
||||||
|
httponly: true,
|
||||||
|
same_site: :lax,
|
||||||
|
secure: false
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
# Set domain for cross-subdomain authentication if we can extract it
|
# Set domain for cross-subdomain authentication if we can extract it
|
||||||
cookie_options[:domain] = domain if domain.present?
|
cookie_options[:domain] = domain if domain.present?
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class OidcController < ApplicationController
|
class OidcController < ApplicationController
|
||||||
# Discovery and JWKS endpoints are public
|
# Discovery and JWKS endpoints are public
|
||||||
allow_unauthenticated_access only: [:discovery, :jwks, :token, :revoke, :userinfo, :logout]
|
# authorize is also unauthenticated to handle prompt=none and prompt=login specially
|
||||||
skip_before_action :verify_authenticity_token, only: [:token, :revoke, :logout]
|
allow_unauthenticated_access only: [:discovery, :jwks, :token, :revoke, :userinfo, :logout, :authorize]
|
||||||
|
skip_before_action :verify_authenticity_token, only: [:token, :revoke, :userinfo, :logout, :authorize, :consent]
|
||||||
|
|
||||||
# Rate limiting to prevent brute force and abuse
|
# Rate limiting to prevent brute force and abuse
|
||||||
rate_limit to: 60, within: 1.minute, only: [:token, :revoke], with: -> {
|
rate_limit to: 60, within: 1.minute, only: [:token, :revoke], with: -> {
|
||||||
@@ -30,10 +31,21 @@ class OidcController < ApplicationController
|
|||||||
id_token_signing_alg_values_supported: ["RS256"],
|
id_token_signing_alg_values_supported: ["RS256"],
|
||||||
scopes_supported: ["openid", "profile", "email", "groups", "offline_access"],
|
scopes_supported: ["openid", "profile", "email", "groups", "offline_access"],
|
||||||
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic"],
|
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic"],
|
||||||
claims_supported: ["sub", "email", "email_verified", "name", "preferred_username", "groups", "admin", "auth_time", "acr", "azp", "at_hash"],
|
claims_supported: [
|
||||||
|
"sub", # Always included
|
||||||
|
"email", # email scope
|
||||||
|
"email_verified", # email scope
|
||||||
|
"name", # profile scope
|
||||||
|
"preferred_username", # profile scope
|
||||||
|
"updated_at", # profile scope
|
||||||
|
"groups" # groups scope
|
||||||
|
# Note: Custom claims are also supported but not listed here
|
||||||
|
# ID-token-only claims (auth_time, acr, azp, at_hash, nonce) are not listed
|
||||||
|
],
|
||||||
code_challenge_methods_supported: ["plain", "S256"],
|
code_challenge_methods_supported: ["plain", "S256"],
|
||||||
backchannel_logout_supported: true,
|
backchannel_logout_supported: true,
|
||||||
backchannel_logout_session_supported: true
|
backchannel_logout_session_supported: true,
|
||||||
|
request_parameter_supported: false
|
||||||
}
|
}
|
||||||
|
|
||||||
render json: config
|
render json: config
|
||||||
@@ -56,32 +68,14 @@ class OidcController < ApplicationController
|
|||||||
code_challenge = params[:code_challenge]
|
code_challenge = params[:code_challenge]
|
||||||
code_challenge_method = params[:code_challenge_method] || "plain"
|
code_challenge_method = params[:code_challenge_method] || "plain"
|
||||||
|
|
||||||
# Validate required parameters
|
# Validate client_id first (required before we can look up the application)
|
||||||
unless client_id.present? && redirect_uri.present? && response_type == "code"
|
# OAuth2 RFC 6749 Section 4.1.2.1: If client_id is missing/invalid, show error page (don't redirect)
|
||||||
error_details = []
|
unless client_id.present?
|
||||||
error_details << "client_id is required" unless client_id.present?
|
render plain: "Invalid request: client_id is required", status: :bad_request
|
||||||
error_details << "redirect_uri is required" unless redirect_uri.present?
|
|
||||||
error_details << "response_type must be 'code'" unless response_type == "code"
|
|
||||||
|
|
||||||
render plain: "Invalid request: #{error_details.join(", ")}", status: :bad_request
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Validate PKCE parameters if present
|
# Find the application by client_id
|
||||||
if code_challenge.present?
|
|
||||||
unless %w[plain S256].include?(code_challenge_method)
|
|
||||||
render plain: "Invalid code_challenge_method: must be 'plain' or 'S256'", status: :bad_request
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
# Validate code challenge format (base64url-encoded, 43-128 characters)
|
|
||||||
unless code_challenge.match?(/\A[A-Za-z0-9\-_]{43,128}\z/)
|
|
||||||
render plain: "Invalid code_challenge format: must be 43-128 characters of base64url encoding", status: :bad_request
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Find the application
|
|
||||||
@application = Application.find_by(client_id: client_id, app_type: "oidc")
|
@application = Application.find_by(client_id: client_id, app_type: "oidc")
|
||||||
unless @application
|
unless @application
|
||||||
# Log all OIDC applications for debugging
|
# Log all OIDC applications for debugging
|
||||||
@@ -99,7 +93,14 @@ class OidcController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Validate redirect URI first (required before we can safely redirect with errors)
|
# Validate redirect_uri presence and format
|
||||||
|
# OAuth2 RFC 6749 Section 4.1.2.1: If redirect_uri is missing/invalid, show error page (don't redirect)
|
||||||
|
unless redirect_uri.present?
|
||||||
|
render plain: "Invalid request: redirect_uri is required", status: :bad_request
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Validate redirect URI matches one of the registered URIs
|
||||||
unless @application.parsed_redirect_uris.include?(redirect_uri)
|
unless @application.parsed_redirect_uris.include?(redirect_uri)
|
||||||
Rails.logger.error "OAuth: Invalid request - redirect URI mismatch. Expected: #{@application.parsed_redirect_uris}, Got: #{redirect_uri}"
|
Rails.logger.error "OAuth: Invalid request - redirect URI mismatch. Expected: #{@application.parsed_redirect_uris}, Got: #{redirect_uri}"
|
||||||
|
|
||||||
@@ -114,6 +115,56 @@ class OidcController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# At this point we have a valid client_id and redirect_uri
|
||||||
|
# All subsequent errors should redirect back to the client with error parameters
|
||||||
|
# per OAuth2 RFC 6749 Section 4.1.2.1
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
# Reject request objects (JWT-encoded authorization parameters)
|
||||||
|
# Per OIDC Core §3.1.2.6: If request parameter is present and not supported,
|
||||||
|
# return request_not_supported error
|
||||||
|
if params[:request].present? || params[:request_uri].present?
|
||||||
|
Rails.logger.error "OAuth: Request object not supported"
|
||||||
|
error_uri = "#{redirect_uri}?error=request_not_supported"
|
||||||
|
error_uri += "&error_description=#{CGI.escape("Request objects are not supported")}"
|
||||||
|
error_uri += "&state=#{CGI.escape(state)}" if state.present?
|
||||||
|
redirect_to error_uri, allow_other_host: true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Validate response_type (now we can safely redirect with error)
|
||||||
|
unless response_type == "code"
|
||||||
|
Rails.logger.error "OAuth: Invalid response_type: #{response_type}"
|
||||||
|
error_uri = "#{redirect_uri}?error=unsupported_response_type"
|
||||||
|
error_uri += "&error_description=#{CGI.escape("Only 'code' response_type is supported")}"
|
||||||
|
error_uri += "&state=#{CGI.escape(state)}" if state.present?
|
||||||
|
redirect_to error_uri, allow_other_host: true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Validate PKCE parameters if present (now we can safely redirect with error)
|
||||||
|
if code_challenge.present?
|
||||||
|
unless %w[plain S256].include?(code_challenge_method)
|
||||||
|
Rails.logger.error "OAuth: Invalid code_challenge_method: #{code_challenge_method}"
|
||||||
|
error_uri = "#{redirect_uri}?error=invalid_request"
|
||||||
|
error_uri += "&error_description=#{CGI.escape("Invalid code_challenge_method: must be 'plain' or 'S256'")}"
|
||||||
|
error_uri += "&state=#{CGI.escape(state)}" if state.present?
|
||||||
|
redirect_to error_uri, allow_other_host: true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Validate code challenge format (base64url-encoded, 43-128 characters)
|
||||||
|
unless code_challenge.match?(/\A[A-Za-z0-9\-_]{43,128}\z/)
|
||||||
|
Rails.logger.error "OAuth: Invalid code_challenge format"
|
||||||
|
error_uri = "#{redirect_uri}?error=invalid_request"
|
||||||
|
error_uri += "&error_description=#{CGI.escape("Invalid code_challenge format: must be 43-128 characters of base64url encoding")}"
|
||||||
|
error_uri += "&state=#{CGI.escape(state)}" if state.present?
|
||||||
|
redirect_to error_uri, allow_other_host: true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Check if application is active (now we can safely redirect with error)
|
# Check if application is active (now we can safely redirect with error)
|
||||||
unless @application.active?
|
unless @application.active?
|
||||||
Rails.logger.error "OAuth: Application is not active: #{@application.name}"
|
Rails.logger.error "OAuth: Application is not active: #{@application.name}"
|
||||||
@@ -125,7 +176,17 @@ class OidcController < ApplicationController
|
|||||||
|
|
||||||
# Check if user is authenticated
|
# Check if user is authenticated
|
||||||
unless authenticated?
|
unless authenticated?
|
||||||
# Store OAuth parameters in session and redirect to sign in
|
# Handle prompt=none - no UI allowed, return error immediately
|
||||||
|
# Per OIDC Core spec §3.1.2.6: If prompt=none and user not authenticated,
|
||||||
|
# return login_required error without showing any UI
|
||||||
|
if params[:prompt] == "none"
|
||||||
|
error_uri = "#{redirect_uri}?error=login_required"
|
||||||
|
error_uri += "&state=#{CGI.escape(state)}" if state.present?
|
||||||
|
redirect_to error_uri, allow_other_host: true
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Normal flow: store OAuth parameters and redirect to sign in
|
||||||
session[:oauth_params] = {
|
session[:oauth_params] = {
|
||||||
client_id: client_id,
|
client_id: client_id,
|
||||||
redirect_uri: redirect_uri,
|
redirect_uri: redirect_uri,
|
||||||
@@ -135,10 +196,57 @@ class OidcController < ApplicationController
|
|||||||
code_challenge: code_challenge,
|
code_challenge: code_challenge,
|
||||||
code_challenge_method: code_challenge_method
|
code_challenge_method: code_challenge_method
|
||||||
}
|
}
|
||||||
|
# Store the current URL (with all OAuth params) for redirect after authentication
|
||||||
|
session[:return_to_after_authenticating] = request.url
|
||||||
redirect_to signin_path, alert: "Please sign in to continue"
|
redirect_to signin_path, alert: "Please sign in to continue"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Handle prompt=login - force re-authentication
|
||||||
|
# Per OIDC Core spec §3.1.2.1: If prompt=login, the Authorization Server MUST prompt
|
||||||
|
# the End-User for reauthentication, even if the End-User is currently authenticated
|
||||||
|
if params[:prompt] == "login"
|
||||||
|
# Destroy current session to force re-authentication
|
||||||
|
# This creates a fresh authentication event with a new auth_time
|
||||||
|
Current.session&.destroy!
|
||||||
|
|
||||||
|
# Clear the session cookie so the user is truly logged out
|
||||||
|
cookies.delete(:session_id)
|
||||||
|
|
||||||
|
# Store the current URL (which contains all OAuth params) for redirect after login
|
||||||
|
# Remove prompt=login to prevent infinite re-auth loop
|
||||||
|
return_url = request.url.sub(/&prompt=login(?=&|$)|\?prompt=login&?/, '\1')
|
||||||
|
# Fix any resulting URL issues (like ?& or & at end)
|
||||||
|
return_url = return_url.gsub("?&", "?").gsub(/[?&]$/, "")
|
||||||
|
session[:return_to_after_authenticating] = return_url
|
||||||
|
|
||||||
|
redirect_to signin_path, alert: "Please sign in to continue"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
# Handle max_age - require re-authentication if session is too old
|
||||||
|
# Per OIDC Core spec §3.1.2.1: If max_age is provided and the auth time is older,
|
||||||
|
# the Authorization Server MUST prompt for reauthentication
|
||||||
|
if params[:max_age].present?
|
||||||
|
max_age_seconds = params[:max_age].to_i
|
||||||
|
# Calculate session age
|
||||||
|
session_age_seconds = Time.current.to_i - Current.session.created_at.to_i
|
||||||
|
|
||||||
|
if session_age_seconds > max_age_seconds
|
||||||
|
# Session is too old - require re-authentication
|
||||||
|
# Store return URL in session (creates new session cookie)
|
||||||
|
|
||||||
|
# Destroy session and clear cookie to force fresh login
|
||||||
|
Current.session&.destroy!
|
||||||
|
cookies.delete(:session_id)
|
||||||
|
|
||||||
|
session[:return_to_after_authenticating] = request.url
|
||||||
|
|
||||||
|
redirect_to signin_path, alert: "Please sign in to continue"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Get the authenticated user
|
# Get the authenticated user
|
||||||
user = Current.session.user
|
user = Current.session.user
|
||||||
|
|
||||||
@@ -419,6 +527,7 @@ class OidcController < ApplicationController
|
|||||||
|
|
||||||
# Generate ID token (JWT) with pairwise SID, at_hash, auth_time, and acr
|
# Generate ID token (JWT) with pairwise SID, at_hash, auth_time, and acr
|
||||||
# auth_time and acr come from the authorization code (captured at /authorize time)
|
# auth_time and acr come from the authorization code (captured at /authorize time)
|
||||||
|
# scopes determine which claims are included (per OIDC Core spec)
|
||||||
id_token = OidcJwtService.generate_id_token(
|
id_token = OidcJwtService.generate_id_token(
|
||||||
user,
|
user,
|
||||||
application,
|
application,
|
||||||
@@ -426,9 +535,14 @@ class OidcController < ApplicationController
|
|||||||
nonce: auth_code.nonce,
|
nonce: auth_code.nonce,
|
||||||
access_token: access_token_record.plaintext_token,
|
access_token: access_token_record.plaintext_token,
|
||||||
auth_time: auth_code.auth_time,
|
auth_time: auth_code.auth_time,
|
||||||
acr: auth_code.acr
|
acr: auth_code.acr,
|
||||||
|
scopes: auth_code.scope
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# RFC6749-5.1: Token endpoint MUST return Cache-Control: no-store
|
||||||
|
response.headers["Cache-Control"] = "no-store"
|
||||||
|
response.headers["Pragma"] = "no-cache"
|
||||||
|
|
||||||
# Return tokens
|
# Return tokens
|
||||||
render json: {
|
render json: {
|
||||||
access_token: access_token_record.plaintext_token, # Opaque token
|
access_token: access_token_record.plaintext_token, # Opaque token
|
||||||
@@ -547,15 +661,21 @@ class OidcController < ApplicationController
|
|||||||
|
|
||||||
# Generate new ID token (JWT with pairwise SID, at_hash, auth_time, acr; no nonce for refresh grants)
|
# Generate new ID token (JWT with pairwise SID, at_hash, auth_time, acr; no nonce for refresh grants)
|
||||||
# auth_time and acr come from the original refresh token (carried over from initial auth)
|
# auth_time and acr come from the original refresh token (carried over from initial auth)
|
||||||
|
# scopes determine which claims are included (per OIDC Core spec)
|
||||||
id_token = OidcJwtService.generate_id_token(
|
id_token = OidcJwtService.generate_id_token(
|
||||||
user,
|
user,
|
||||||
application,
|
application,
|
||||||
consent: consent,
|
consent: consent,
|
||||||
access_token: new_access_token.plaintext_token,
|
access_token: new_access_token.plaintext_token,
|
||||||
auth_time: refresh_token_record.auth_time,
|
auth_time: refresh_token_record.auth_time,
|
||||||
acr: refresh_token_record.acr
|
acr: refresh_token_record.acr,
|
||||||
|
scopes: refresh_token_record.scope
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# RFC6749-5.1: Token endpoint MUST return Cache-Control: no-store
|
||||||
|
response.headers["Cache-Control"] = "no-store"
|
||||||
|
response.headers["Pragma"] = "no-cache"
|
||||||
|
|
||||||
# Return new tokens
|
# Return new tokens
|
||||||
render json: {
|
render json: {
|
||||||
access_token: new_access_token.plaintext_token, # Opaque token
|
access_token: new_access_token.plaintext_token, # Opaque token
|
||||||
@@ -569,17 +689,22 @@ class OidcController < ApplicationController
|
|||||||
render json: {error: "invalid_grant"}, status: :bad_request
|
render json: {error: "invalid_grant"}, status: :bad_request
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /oauth/userinfo
|
# GET/POST /oauth/userinfo
|
||||||
|
# OIDC Core spec: UserInfo endpoint MUST support GET, SHOULD support POST
|
||||||
def userinfo
|
def userinfo
|
||||||
# Extract access token from Authorization header
|
# Extract access token from Authorization header or POST body
|
||||||
auth_header = request.headers["Authorization"]
|
# RFC 6750: Bearer token can be in Authorization header, request body, or query string
|
||||||
unless auth_header&.start_with?("Bearer ")
|
token = if request.headers["Authorization"]&.start_with?("Bearer ")
|
||||||
|
request.headers["Authorization"].sub("Bearer ", "")
|
||||||
|
elsif request.params["access_token"].present?
|
||||||
|
request.params["access_token"]
|
||||||
|
end
|
||||||
|
|
||||||
|
unless token
|
||||||
head :unauthorized
|
head :unauthorized
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
token = auth_header.sub("Bearer ", "")
|
|
||||||
|
|
||||||
# Find and validate access token (opaque token with BCrypt hashing)
|
# Find and validate access token (opaque token with BCrypt hashing)
|
||||||
access_token = OidcAccessToken.find_by_token(token)
|
access_token = OidcAccessToken.find_by_token(token)
|
||||||
unless access_token&.active?
|
unless access_token&.active?
|
||||||
@@ -605,17 +730,35 @@ class OidcController < ApplicationController
|
|||||||
consent = OidcUserConsent.find_by(user: user, application: access_token.application)
|
consent = OidcUserConsent.find_by(user: user, application: access_token.application)
|
||||||
subject = consent&.sid || user.id.to_s
|
subject = consent&.sid || user.id.to_s
|
||||||
|
|
||||||
# Return user claims
|
# Parse scopes from access token (space-separated string)
|
||||||
|
requested_scopes = access_token.scope.to_s.split
|
||||||
|
|
||||||
|
# Return user claims (filter by scope per OIDC Core spec)
|
||||||
|
# Required claims (always included)
|
||||||
claims = {
|
claims = {
|
||||||
sub: subject,
|
sub: subject
|
||||||
email: user.email_address,
|
|
||||||
email_verified: true,
|
|
||||||
preferred_username: user.email_address,
|
|
||||||
name: user.name.presence || user.email_address
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add groups if user has any
|
# Email claims (only if 'email' scope requested)
|
||||||
if user.groups.any?
|
if requested_scopes.include?("email")
|
||||||
|
claims[:email] = user.email_address
|
||||||
|
claims[:email_verified] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
# Profile claims (only if 'profile' scope requested)
|
||||||
|
# Per OIDC Core spec section 5.4, include available profile claims
|
||||||
|
# Only include claims we have data for - omit unknown claims rather than returning null
|
||||||
|
if requested_scopes.include?("profile")
|
||||||
|
# Use username if available, otherwise email as preferred_username
|
||||||
|
claims[:preferred_username] = user.username.presence || user.email_address
|
||||||
|
# Name: use stored name or fall back to email
|
||||||
|
claims[:name] = user.name.presence || user.email_address
|
||||||
|
# Time the user's information was last updated
|
||||||
|
claims[:updated_at] = user.updated_at.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
# Groups claim (only if 'groups' scope requested)
|
||||||
|
if requested_scopes.include?("groups") && user.groups.any?
|
||||||
claims[:groups] = user.groups.pluck(:name)
|
claims[:groups] = user.groups.pluck(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -631,6 +774,10 @@ class OidcController < ApplicationController
|
|||||||
application = access_token.application
|
application = access_token.application
|
||||||
claims.merge!(application.custom_claims_for_user(user))
|
claims.merge!(application.custom_claims_for_user(user))
|
||||||
|
|
||||||
|
# Security: Don't cache user data responses
|
||||||
|
response.headers["Cache-Control"] = "no-store"
|
||||||
|
response.headers["Pragma"] = "no-cache"
|
||||||
|
|
||||||
render json: claims
|
render json: claims
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -775,12 +922,12 @@ class OidcController < ApplicationController
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Validate code verifier format (base64url-encoded, 43-128 characters)
|
# Validate code verifier format (per RFC 7636: [A-Za-z0-9\-._~], 43-128 characters)
|
||||||
unless code_verifier.match?(/\A[A-Za-z0-9\-_]{43,128}\z/)
|
unless code_verifier.match?(/\A[A-Za-z0-9\.\-_~]{43,128}\z/)
|
||||||
return {
|
return {
|
||||||
valid: false,
|
valid: false,
|
||||||
error: "invalid_request",
|
error: "invalid_request",
|
||||||
error_description: "Invalid code_verifier format. Must be 43-128 characters of base64url encoding",
|
error_description: "Invalid code_verifier format. Must be 43-128 characters [A-Z/a-z/0-9/-/./_/~]",
|
||||||
status: :bad_request
|
status: :bad_request
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,6 +14,20 @@ class SessionsController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Extract login_hint from the return URL for pre-filling the email field (OIDC spec)
|
||||||
|
@login_hint = nil
|
||||||
|
if session[:return_to_after_authenticating].present?
|
||||||
|
begin
|
||||||
|
uri = URI.parse(session[:return_to_after_authenticating])
|
||||||
|
if uri.query.present?
|
||||||
|
query_params = CGI.parse(uri.query)
|
||||||
|
@login_hint = query_params["login_hint"]&.first
|
||||||
|
end
|
||||||
|
rescue URI::InvalidURIError
|
||||||
|
# Ignore parsing errors
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # render HTML login page
|
format.html # render HTML login page
|
||||||
format.json { render json: {error: "Authentication required"}, status: :unauthorized }
|
format.json { render json: {error: "Authentication required"}, status: :unauthorized }
|
||||||
@@ -73,7 +87,10 @@ class SessionsController < ApplicationController
|
|||||||
|
|
||||||
# Sign in successful (password only)
|
# Sign in successful (password only)
|
||||||
start_new_session_for user, acr: "1"
|
start_new_session_for user, acr: "1"
|
||||||
redirect_to after_authentication_url, notice: "Signed in successfully.", allow_other_host: true
|
|
||||||
|
# Use status: :see_other to ensure browser makes a GET request
|
||||||
|
# This prevents Turbo from converting it to a TURBO_STREAM request
|
||||||
|
redirect_to after_authentication_url, notice: "Signed in successfully.", allow_other_host: true, status: :see_other
|
||||||
end
|
end
|
||||||
|
|
||||||
def verify_totp
|
def verify_totp
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class OidcJwtService
|
|||||||
|
|
||||||
class << self
|
class << self
|
||||||
# Generate an ID token (JWT) for the user
|
# Generate an ID token (JWT) for the user
|
||||||
def generate_id_token(user, application, consent: nil, nonce: nil, access_token: nil, auth_time: nil, acr: nil)
|
def generate_id_token(user, application, consent: nil, nonce: nil, access_token: nil, auth_time: nil, acr: nil, scopes: "openid")
|
||||||
now = Time.current.to_i
|
now = Time.current.to_i
|
||||||
# Use application's configured ID token TTL (defaults to 1 hour)
|
# Use application's configured ID token TTL (defaults to 1 hour)
|
||||||
ttl = application.id_token_expiry_seconds
|
ttl = application.id_token_expiry_seconds
|
||||||
@@ -11,18 +11,23 @@ class OidcJwtService
|
|||||||
# Use pairwise SID from consent if available, fallback to user ID
|
# Use pairwise SID from consent if available, fallback to user ID
|
||||||
subject = consent&.sid || user.id.to_s
|
subject = consent&.sid || user.id.to_s
|
||||||
|
|
||||||
|
# Parse scopes (space-separated string)
|
||||||
|
requested_scopes = scopes.to_s.split
|
||||||
|
|
||||||
|
# Required claims (always included per OIDC Core spec)
|
||||||
payload = {
|
payload = {
|
||||||
iss: issuer_url,
|
iss: issuer_url,
|
||||||
sub: subject,
|
sub: subject,
|
||||||
aud: application.client_id,
|
aud: application.client_id,
|
||||||
exp: now + ttl,
|
exp: now + ttl,
|
||||||
iat: now,
|
iat: now
|
||||||
email: user.email_address,
|
|
||||||
email_verified: true,
|
|
||||||
preferred_username: user.username.presence || user.email_address,
|
|
||||||
name: user.name.presence || user.email_address
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# NOTE: Email and profile claims are NOT included in the ID token for authorization code flow
|
||||||
|
# Per OIDC Core spec §5.4, these claims should only be returned via the UserInfo endpoint
|
||||||
|
# For implicit flow (response_type=id_token), claims would be included here, but we only
|
||||||
|
# support authorization code flow, so these claims are omitted from the ID token.
|
||||||
|
|
||||||
# Add nonce if provided (OIDC requires this for implicit flow)
|
# Add nonce if provided (OIDC requires this for implicit flow)
|
||||||
payload[:nonce] = nonce if nonce.present?
|
payload[:nonce] = nonce if nonce.present?
|
||||||
|
|
||||||
@@ -44,12 +49,13 @@ class OidcJwtService
|
|||||||
payload[:at_hash] = at_hash
|
payload[:at_hash] = at_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add groups if user has any
|
# Groups claims (only if 'groups' scope requested)
|
||||||
if user.groups.any?
|
if requested_scopes.include?("groups") && user.groups.any?
|
||||||
payload[:groups] = user.groups.pluck(:name)
|
payload[:groups] = user.groups.pluck(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Merge custom claims from groups (arrays are combined, not overwritten)
|
# Merge custom claims from groups (arrays are combined, not overwritten)
|
||||||
|
# Note: Custom claims from groups are always merged (not scope-dependent)
|
||||||
user.groups.each do |group|
|
user.groups.each do |group|
|
||||||
payload = deep_merge_claims(payload, group.parsed_custom_claims)
|
payload = deep_merge_claims(payload, group.parsed_custom_claims)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
autofocus: true,
|
autofocus: true,
|
||||||
autocomplete: "username",
|
autocomplete: "username",
|
||||||
placeholder: "your@email.com",
|
placeholder: "your@email.com",
|
||||||
value: params[:email_address],
|
value: @login_hint || params[:email_address],
|
||||||
data: { action: "blur->webauthn#checkWebAuthnSupport change->webauthn#checkWebAuthnSupport" },
|
data: { action: "blur->webauthn#checkWebAuthnSupport change->webauthn#checkWebAuthnSupport" },
|
||||||
class: "block shadow-sm rounded-md border border-gray-400 focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
|
class: "block shadow-sm rounded-md border border-gray-400 focus:outline-blue-600 px-3 py-2 mt-2 w-full" %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Clinch
|
module Clinch
|
||||||
VERSION = "0.8.2"
|
VERSION = "0.8.4"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,11 +26,11 @@ Rails.application.routes.draw do
|
|||||||
# OIDC (OpenID Connect) routes
|
# OIDC (OpenID Connect) routes
|
||||||
get "/.well-known/openid-configuration", to: "oidc#discovery"
|
get "/.well-known/openid-configuration", to: "oidc#discovery"
|
||||||
get "/.well-known/jwks.json", to: "oidc#jwks"
|
get "/.well-known/jwks.json", to: "oidc#jwks"
|
||||||
get "/oauth/authorize", to: "oidc#authorize"
|
match "/oauth/authorize", to: "oidc#authorize", via: [:get, :post]
|
||||||
post "/oauth/authorize/consent", to: "oidc#consent", as: :oauth_consent
|
post "/oauth/authorize/consent", to: "oidc#consent", as: :oauth_consent
|
||||||
post "/oauth/token", to: "oidc#token"
|
post "/oauth/token", to: "oidc#token"
|
||||||
post "/oauth/revoke", to: "oidc#revoke"
|
post "/oauth/revoke", to: "oidc#revoke"
|
||||||
get "/oauth/userinfo", to: "oidc#userinfo"
|
match "/oauth/userinfo", to: "oidc#userinfo", via: [:get, :post]
|
||||||
get "/logout", to: "oidc#logout"
|
get "/logout", to: "oidc#logout"
|
||||||
|
|
||||||
# ForwardAuth / Trusted Header SSO
|
# ForwardAuth / Trusted Header SSO
|
||||||
|
|||||||
@@ -24,6 +24,18 @@ This checklist ensures Clinch meets security, quality, and documentation standar
|
|||||||
- [x] **importmap audit** - JavaScript dependency scanning
|
- [x] **importmap audit** - JavaScript dependency scanning
|
||||||
- CI: Runs on every PR and push to main
|
- CI: Runs on every PR and push to main
|
||||||
|
|
||||||
|
- [x] **Trivy** - Container image vulnerability scanning
|
||||||
|
- Scans Docker images for OS and system package vulnerabilities
|
||||||
|
- CI: Builds and scans image on every PR and push to main
|
||||||
|
- Results uploaded to GitHub Security tab
|
||||||
|
|
||||||
|
- [x] **Dependabot** - Automated dependency updates
|
||||||
|
- Creates PRs for outdated dependencies
|
||||||
|
- Enabled for Ruby gems and GitHub Actions
|
||||||
|
|
||||||
|
- [x] **GitHub Secret Scanning** - Detects leaked credentials
|
||||||
|
- Push protection enabled to block commits with secrets
|
||||||
|
|
||||||
- [x] **Test Coverage** - SimpleCov integration
|
- [x] **Test Coverage** - SimpleCov integration
|
||||||
- Command: `COVERAGE=1 bin/rails test`
|
- Command: `COVERAGE=1 bin/rails test`
|
||||||
- Coverage report: `coverage/index.html`
|
- Coverage report: `coverage/index.html`
|
||||||
@@ -192,21 +204,32 @@ This checklist ensures Clinch meets security, quality, and documentation standar
|
|||||||
- [ ] Document backup code security (single-use, store securely)
|
- [ ] Document backup code security (single-use, store securely)
|
||||||
- [ ] Document admin password security requirements
|
- [ ] Document admin password security requirements
|
||||||
|
|
||||||
### Future Security Enhancements
|
### Future Security Enhancements (Post-Beta)
|
||||||
- [ ] Rate limiting on authentication endpoints
|
- [x] Rate limiting on authentication endpoints (comprehensive coverage implemented)
|
||||||
- [ ] Account lockout after N failed attempts
|
- [ ] Account lockout after N failed attempts (rate limiting provides similar protection)
|
||||||
- [ ] Admin audit logging
|
- [ ] Admin audit logging
|
||||||
- [ ] Security event notifications
|
- [ ] Security event notifications (email/webhook alerts for suspicious activity)
|
||||||
- [ ] Brute force detection
|
- [ ] Advanced brute force detection (pattern analysis beyond rate limiting)
|
||||||
- [ ] Suspicious login detection
|
- [ ] Suspicious login detection (geolocation, device fingerprinting)
|
||||||
- [ ] IP allowlist/blocklist
|
- [ ] IP allowlist/blocklist
|
||||||
|
|
||||||
## External Security Review
|
## Protocol Conformance & Security Review
|
||||||
|
|
||||||
- [ ] Consider bug bounty or security audit
|
**Protocol Conformance (Completed):**
|
||||||
- [ ] Penetration testing for OIDC flows
|
- [x] **OpenID Connect Conformance Testing** - [48/48 tests passed](https://www.certification.openid.net/log-detail.html?log=TZ8vOG0kf35lUiD)
|
||||||
- [ ] WebAuthn implementation review
|
- OIDC authorization code flow ✅
|
||||||
- [ ] Token security review
|
- PKCE flow ✅
|
||||||
|
- Token security (ID tokens, access tokens, refresh tokens) ✅
|
||||||
|
- Scope-based claim filtering ✅
|
||||||
|
- Standard OIDC claims and metadata ✅
|
||||||
|
- Proper OAuth2 error handling (redirect vs. error page) ✅
|
||||||
|
|
||||||
|
**External Security Review (Optional for Post-Beta):**
|
||||||
|
- [ ] Traditional security audit or penetration test
|
||||||
|
- Note: OIDC conformance tests protocol compliance, not security vulnerabilities
|
||||||
|
- A dedicated security audit would test for injection, XSS, auth bypasses, etc.
|
||||||
|
- [ ] Bug bounty program
|
||||||
|
- [ ] WebAuthn implementation security review
|
||||||
|
|
||||||
## Documentation for Users
|
## Documentation for Users
|
||||||
|
|
||||||
@@ -227,7 +250,8 @@ To move from "experimental" to "Beta", the following must be completed:
|
|||||||
- [x] Basic documentation complete
|
- [x] Basic documentation complete
|
||||||
- [x] Backup/restore documentation
|
- [x] Backup/restore documentation
|
||||||
- [x] Production deployment guide
|
- [x] Production deployment guide
|
||||||
- [ ] At least one external security review or penetration test
|
- [x] Protocol conformance validation
|
||||||
|
- [OpenID Connect Conformance Testing](https://www.certification.openid.net/log-detail.html?log=TZ8vOG0kf35lUiD) - **48 tests PASSED**, 0 failures, 0 warnings
|
||||||
|
|
||||||
**Important (Should have for Beta):**
|
**Important (Should have for Beta):**
|
||||||
- [x] Rate limiting on auth endpoints
|
- [x] Rate limiting on auth endpoints
|
||||||
@@ -238,26 +262,42 @@ To move from "experimental" to "Beta", the following must be completed:
|
|||||||
**Nice to have (Can defer to post-Beta):**
|
**Nice to have (Can defer to post-Beta):**
|
||||||
- [ ] Bug bounty program
|
- [ ] Bug bounty program
|
||||||
- [ ] Advanced monitoring/alerting
|
- [ ] Advanced monitoring/alerting
|
||||||
- [ ] Automated security testing in CI beyond brakeman/bundler-audit
|
- [x] Automated security testing in CI beyond brakeman/bundler-audit
|
||||||
|
- [x] Dependabot (automated dependency updates)
|
||||||
|
- [x] GitHub Secret Scanning (automatic with push protection enabled)
|
||||||
|
- [x] Container image scanning (Trivy scans Docker images for OS/system vulnerabilities)
|
||||||
|
- [ ] DAST/Dynamic testing (OWASP ZAP) - optional for post-Beta
|
||||||
|
|
||||||
## Status Summary
|
## Status Summary
|
||||||
|
|
||||||
**Current Status:** Pre-Beta / Experimental
|
**Current Status:** Ready for Beta Release 🎉
|
||||||
|
|
||||||
**Strengths:**
|
**Strengths:**
|
||||||
- ✅ Comprehensive security tooling in place
|
- ✅ Comprehensive security tooling in place
|
||||||
- ✅ Strong test coverage (341 tests, 1349 assertions)
|
- ✅ Strong test coverage (374 tests, 1538 assertions)
|
||||||
- ✅ Modern security features (PKCE, token rotation, WebAuthn)
|
- ✅ Modern security features (PKCE, token rotation, WebAuthn)
|
||||||
- ✅ Clean security scans (brakeman, bundler-audit)
|
- ✅ Clean security scans (brakeman, bundler-audit, Trivy)
|
||||||
- ✅ Well-documented codebase
|
- ✅ Well-documented codebase
|
||||||
|
- ✅ **OpenID Connect Conformance certified** - 48/48 tests passed
|
||||||
|
|
||||||
**Before Beta Release:**
|
**All Critical Requirements Met:**
|
||||||
- 🔶 External security review recommended
|
- All automated security scans passing ✅
|
||||||
- 🔶 Admin audit logging (optional)
|
- All tests passing (374 tests, 1542 assertions) ✅
|
||||||
|
- Core features implemented and tested ✅
|
||||||
|
- Documentation complete ✅
|
||||||
|
- Production deployment guide ✅
|
||||||
|
- Protocol conformance validation complete ✅
|
||||||
|
|
||||||
**Recommendation:** Consider Beta status after:
|
**Optional for Post-Beta:**
|
||||||
1. External security review or penetration testing
|
- Admin audit logging
|
||||||
2. Real-world testing period
|
- Traditional security audit/penetration test
|
||||||
|
- Bug bounty program
|
||||||
|
- Advanced monitoring/alerting
|
||||||
|
|
||||||
|
**Recommendation:**
|
||||||
|
Clinch meets all critical requirements for Beta release. The OIDC implementation is protocol-compliant (48/48 conformance tests passed), security scans are clean, and the codebase has strong test coverage.
|
||||||
|
|
||||||
|
For production use in security-sensitive environments, consider a traditional security audit or penetration test post-Beta to validate against common vulnerabilities (injection, XSS, auth bypasses, etc.) beyond protocol conformance.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -91,8 +91,10 @@ class OidcPkceControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
get "/oauth/authorize", params: auth_params
|
get "/oauth/authorize", params: auth_params
|
||||||
|
|
||||||
assert_response :bad_request
|
# Should redirect back to client with error parameters (OAuth2 spec)
|
||||||
assert_match(/Invalid code_challenge_method/, @response.body)
|
assert_response :redirect
|
||||||
|
assert_match(/error=invalid_request/, @response.location)
|
||||||
|
assert_match(/error_description=.*code_challenge_method/, @response.location)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "authorization endpoint rejects invalid code_challenge format" do
|
test "authorization endpoint rejects invalid code_challenge format" do
|
||||||
@@ -108,8 +110,10 @@ class OidcPkceControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
get "/oauth/authorize", params: auth_params
|
get "/oauth/authorize", params: auth_params
|
||||||
|
|
||||||
assert_response :bad_request
|
# Should redirect back to client with error parameters (OAuth2 spec)
|
||||||
assert_match(/Invalid code_challenge format/, @response.body)
|
assert_response :redirect
|
||||||
|
assert_match(/error=invalid_request/, @response.location)
|
||||||
|
assert_match(/error_description=.*code_challenge.*format/, @response.location)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "token endpoint requires code_verifier when PKCE was used (S256)" do
|
test "token endpoint requires code_verifier when PKCE was used (S256)" do
|
||||||
|
|||||||
@@ -228,7 +228,11 @@ class OidcRefreshTokenControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
assert_equal @user.id.to_s, json["sub"]
|
|
||||||
|
# Should return pairwise SID from consent (alice has consent for kavita_app in fixtures)
|
||||||
|
consent = OidcUserConsent.find_by(user: @user, application: @application)
|
||||||
|
expected_sub = consent&.sid || @user.id.to_s
|
||||||
|
assert_equal expected_sub, json["sub"]
|
||||||
assert_equal @user.email_address, json["email"]
|
assert_equal @user.email_address, json["email"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
269
test/controllers/oidc_userinfo_controller_test.rb
Normal file
269
test/controllers/oidc_userinfo_controller_test.rb
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class OidcUserinfoControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
def setup
|
||||||
|
@user = users(:alice)
|
||||||
|
@application = applications(:kavita_app)
|
||||||
|
|
||||||
|
# Add user to a group for groups claim testing
|
||||||
|
@admin_group = groups(:admin_group)
|
||||||
|
@user.groups << @admin_group unless @user.groups.include?(@admin_group)
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
# Clean up
|
||||||
|
OidcAccessToken.where(user: @user, application: @application).destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# HTTP Method Tests (GET and POST)
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
test "userinfo endpoint accepts GET requests" do
|
||||||
|
access_token = create_access_token("openid email profile")
|
||||||
|
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
assert json["sub"].present?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo endpoint accepts POST requests" do
|
||||||
|
access_token = create_access_token("openid email profile")
|
||||||
|
|
||||||
|
post "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
assert json["sub"].present?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo endpoint accepts POST with access_token in body" do
|
||||||
|
access_token = create_access_token("openid email profile")
|
||||||
|
|
||||||
|
post "/oauth/userinfo", params: {
|
||||||
|
access_token: access_token.plaintext_token
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
assert json["sub"].present?
|
||||||
|
end
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Scope-Based Claim Filtering Tests
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
test "userinfo with openid scope only returns minimal claims" do
|
||||||
|
access_token = create_access_token("openid")
|
||||||
|
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
|
||||||
|
# Required claims
|
||||||
|
assert json["sub"].present?, "Should include sub claim"
|
||||||
|
|
||||||
|
# Scope-dependent claims should NOT be present
|
||||||
|
assert_nil json["email"], "Should not include email without email scope"
|
||||||
|
assert_nil json["email_verified"], "Should not include email_verified without email scope"
|
||||||
|
assert_nil json["name"], "Should not include name without profile scope"
|
||||||
|
assert_nil json["preferred_username"], "Should not include preferred_username without profile scope"
|
||||||
|
assert_nil json["groups"], "Should not include groups without groups scope"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo with email scope includes email claims" do
|
||||||
|
access_token = create_access_token("openid email")
|
||||||
|
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
|
||||||
|
# Required claims
|
||||||
|
assert json["sub"].present?
|
||||||
|
|
||||||
|
# Email claims should be present
|
||||||
|
assert_equal @user.email_address, json["email"], "Should include email with email scope"
|
||||||
|
assert_equal true, json["email_verified"], "Should include email_verified with email scope"
|
||||||
|
|
||||||
|
# Profile claims should NOT be present
|
||||||
|
assert_nil json["name"], "Should not include name without profile scope"
|
||||||
|
assert_nil json["preferred_username"], "Should not include preferred_username without profile scope"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo with profile scope includes profile claims" do
|
||||||
|
access_token = create_access_token("openid profile")
|
||||||
|
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
|
||||||
|
# Required claims
|
||||||
|
assert json["sub"].present?
|
||||||
|
|
||||||
|
# Profile claims we support should be present
|
||||||
|
assert json["name"].present?, "Should include name with profile scope"
|
||||||
|
assert json["preferred_username"].present?, "Should include preferred_username with profile scope"
|
||||||
|
assert json["updated_at"].present?, "Should include updated_at with profile scope"
|
||||||
|
|
||||||
|
# Email claims should NOT be present
|
||||||
|
assert_nil json["email"], "Should not include email without email scope"
|
||||||
|
assert_nil json["email_verified"], "Should not include email_verified without email scope"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo with groups scope includes groups claim" do
|
||||||
|
access_token = create_access_token("openid groups")
|
||||||
|
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
|
||||||
|
# Required claims
|
||||||
|
assert json["sub"].present?
|
||||||
|
|
||||||
|
# Groups claim should be present
|
||||||
|
assert json["groups"].present?, "Should include groups with groups scope"
|
||||||
|
assert_includes json["groups"], "Administrators", "Should include user's groups"
|
||||||
|
|
||||||
|
# Email and profile claims should NOT be present
|
||||||
|
assert_nil json["email"], "Should not include email without email scope"
|
||||||
|
assert_nil json["name"], "Should not include name without profile scope"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo with multiple scopes includes all requested claims" do
|
||||||
|
access_token = create_access_token("openid email profile groups")
|
||||||
|
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
|
||||||
|
# All scope-based claims should be present
|
||||||
|
assert json["sub"].present?
|
||||||
|
assert json["email"].present?, "Should include email"
|
||||||
|
assert json["email_verified"].present?, "Should include email_verified"
|
||||||
|
assert json["name"].present?, "Should include name"
|
||||||
|
assert json["preferred_username"].present?, "Should include preferred_username"
|
||||||
|
assert json["groups"].present?, "Should include groups"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo returns same filtered claims for GET and POST" do
|
||||||
|
access_token = create_access_token("openid email")
|
||||||
|
|
||||||
|
# GET request
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
get_json = JSON.parse(response.body)
|
||||||
|
|
||||||
|
# POST request
|
||||||
|
post "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
post_json = JSON.parse(response.body)
|
||||||
|
|
||||||
|
# Both should return the same claims
|
||||||
|
assert_equal get_json, post_json, "GET and POST should return identical claims"
|
||||||
|
end
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Authentication Tests
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
test "userinfo endpoint requires Bearer token" do
|
||||||
|
get "/oauth/userinfo"
|
||||||
|
|
||||||
|
assert_response :unauthorized
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo endpoint rejects invalid token" do
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer invalid_token_12345"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :unauthorized
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo endpoint rejects expired token" do
|
||||||
|
access_token = create_access_token("openid email profile")
|
||||||
|
|
||||||
|
# Expire the token
|
||||||
|
access_token.update!(expires_at: 1.hour.ago)
|
||||||
|
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :unauthorized
|
||||||
|
end
|
||||||
|
|
||||||
|
test "userinfo endpoint rejects revoked token" do
|
||||||
|
access_token = create_access_token("openid email profile")
|
||||||
|
|
||||||
|
# Revoke the token
|
||||||
|
access_token.revoke!
|
||||||
|
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :unauthorized
|
||||||
|
end
|
||||||
|
|
||||||
|
# ============================================================================
|
||||||
|
# Pairwise Subject Identifier Test
|
||||||
|
# ============================================================================
|
||||||
|
|
||||||
|
test "userinfo returns pairwise SID when consent exists" do
|
||||||
|
access_token = create_access_token("openid")
|
||||||
|
|
||||||
|
# Find existing consent or create new one (ensure it has a SID)
|
||||||
|
consent = OidcUserConsent.find_or_initialize_by(
|
||||||
|
user: @user,
|
||||||
|
application: @application
|
||||||
|
)
|
||||||
|
consent.scopes_granted ||= "openid"
|
||||||
|
consent.save!
|
||||||
|
|
||||||
|
# Reload to get the auto-generated SID
|
||||||
|
consent.reload
|
||||||
|
|
||||||
|
get "/oauth/userinfo", headers: {
|
||||||
|
"Authorization" => "Bearer #{access_token.plaintext_token}"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
assert_equal consent.sid, json["sub"], "Should use pairwise SID from consent"
|
||||||
|
assert consent.sid.present?, "Consent should have a SID"
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def create_access_token(scope)
|
||||||
|
OidcAccessToken.create!(
|
||||||
|
application: @application,
|
||||||
|
user: @user,
|
||||||
|
scope: scope
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
2
test/fixtures/oidc_user_consents.yml
vendored
2
test/fixtures/oidc_user_consents.yml
vendored
@@ -5,9 +5,11 @@ alice_consent:
|
|||||||
application: kavita_app
|
application: kavita_app
|
||||||
scopes_granted: openid profile email
|
scopes_granted: openid profile email
|
||||||
granted_at: 2025-10-24 16:57:39
|
granted_at: 2025-10-24 16:57:39
|
||||||
|
sid: alice-kavita-sid-12345
|
||||||
|
|
||||||
bob_consent:
|
bob_consent:
|
||||||
user: bob
|
user: bob
|
||||||
application: another_app
|
application: another_app
|
||||||
scopes_granted: openid email groups
|
scopes_granted: openid email groups
|
||||||
granted_at: 2025-10-24 16:57:39
|
granted_at: 2025-10-24 16:57:39
|
||||||
|
sid: bob-another-sid-67890
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should generate id token with required claims" do
|
test "should generate id token with required claims" do
|
||||||
token = @service.generate_id_token(@user, @application)
|
token = @service.generate_id_token(@user, @application, scopes: "openid email profile")
|
||||||
|
|
||||||
assert_not_nil token, "Should generate token"
|
assert_not_nil token, "Should generate token"
|
||||||
assert token.length > 100, "Token should be substantial"
|
assert token.length > 100, "Token should be substantial"
|
||||||
@@ -88,7 +88,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
admin_group = groups(:admin_group)
|
admin_group = groups(:admin_group)
|
||||||
@user.groups << admin_group unless @user.groups.include?(admin_group)
|
@user.groups << admin_group unless @user.groups.include?(admin_group)
|
||||||
|
|
||||||
token = @service.generate_id_token(@user, @application)
|
token = @service.generate_id_token(@user, @application, scopes: "openid groups")
|
||||||
|
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
assert_includes decoded["groups"], "Administrators", "Should include user's groups"
|
assert_includes decoded["groups"], "Administrators", "Should include user's groups"
|
||||||
@@ -248,10 +248,10 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should handle access token generation" do
|
test "should handle access token generation" do
|
||||||
token = @service.generate_id_token(@user, @application)
|
token = @service.generate_id_token(@user, @application, scopes: "openid email")
|
||||||
|
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
# ID tokens always include email_verified
|
# ID tokens include email_verified when email scope is requested
|
||||||
assert_includes decoded.keys, "email_verified"
|
assert_includes decoded.keys, "email_verified"
|
||||||
assert_equal @user.id.to_s, decoded["sub"], "Should decode subject correctly"
|
assert_equal @user.id.to_s, decoded["sub"], "Should decode subject correctly"
|
||||||
assert_equal @application.client_id, decoded["aud"], "Should decode audience correctly"
|
assert_equal @application.client_id, decoded["aud"], "Should decode audience correctly"
|
||||||
@@ -278,7 +278,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
custom_claims: {app_groups: ["admin"], library_access: "all"}
|
custom_claims: {app_groups: ["admin"], library_access: "all"}
|
||||||
)
|
)
|
||||||
|
|
||||||
token = @service.generate_id_token(user, app)
|
token = @service.generate_id_token(user, app, scopes: "openid email profile groups")
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
assert_equal ["admin"], decoded["app_groups"]
|
assert_equal ["admin"], decoded["app_groups"]
|
||||||
@@ -305,7 +305,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
custom_claims: {role: "admin", app_specific: true}
|
custom_claims: {role: "admin", app_specific: true}
|
||||||
)
|
)
|
||||||
|
|
||||||
token = @service.generate_id_token(user, app)
|
token = @service.generate_id_token(user, app, scopes: "openid email profile groups")
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
# App-specific claim should win
|
# App-specific claim should win
|
||||||
@@ -330,7 +330,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
# User adds roles: ["admin"]
|
# User adds roles: ["admin"]
|
||||||
user.update!(custom_claims: {"roles" => ["admin"], "permissions" => ["write"]})
|
user.update!(custom_claims: {"roles" => ["admin"], "permissions" => ["write"]})
|
||||||
|
|
||||||
token = @service.generate_id_token(user, app)
|
token = @service.generate_id_token(user, app, scopes: "openid email profile groups")
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
# Roles should be combined (not overwritten)
|
# Roles should be combined (not overwritten)
|
||||||
@@ -360,7 +360,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
# User adds roles: ["admin"]
|
# User adds roles: ["admin"]
|
||||||
user.update!(custom_claims: {"roles" => ["admin"]})
|
user.update!(custom_claims: {"roles" => ["admin"]})
|
||||||
|
|
||||||
token = @service.generate_id_token(user, app)
|
token = @service.generate_id_token(user, app, scopes: "openid email profile groups")
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
# All roles should be combined
|
# All roles should be combined
|
||||||
@@ -382,7 +382,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
# User also has "user" role (duplicate)
|
# User also has "user" role (duplicate)
|
||||||
user.update!(custom_claims: {"roles" => ["user", "admin"]})
|
user.update!(custom_claims: {"roles" => ["user", "admin"]})
|
||||||
|
|
||||||
token = @service.generate_id_token(user, app)
|
token = @service.generate_id_token(user, app, scopes: "openid email profile groups")
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
# "user" should only appear once
|
# "user" should only appear once
|
||||||
@@ -404,7 +404,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
# User overrides max_items and theme, adds to roles
|
# User overrides max_items and theme, adds to roles
|
||||||
user.update!(custom_claims: {"roles" => ["admin"], "max_items" => 100, "theme" => "dark"})
|
user.update!(custom_claims: {"roles" => ["admin"], "max_items" => 100, "theme" => "dark"})
|
||||||
|
|
||||||
token = @service.generate_id_token(user, app)
|
token = @service.generate_id_token(user, app, scopes: "openid email profile groups")
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
# Arrays should be combined
|
# Arrays should be combined
|
||||||
@@ -438,7 +438,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
token = @service.generate_id_token(user, app)
|
token = @service.generate_id_token(user, app, scopes: "openid email profile groups")
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
# Nested hashes should be deep merged
|
# Nested hashes should be deep merged
|
||||||
@@ -467,7 +467,7 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
custom_claims: {"roles" => ["app_admin"]}
|
custom_claims: {"roles" => ["app_admin"]}
|
||||||
)
|
)
|
||||||
|
|
||||||
token = @service.generate_id_token(user, app)
|
token = @service.generate_id_token(user, app, scopes: "openid email profile groups")
|
||||||
decoded = JWT.decode(token, nil, false).first
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
# All three sources should be combined
|
# All three sources should be combined
|
||||||
@@ -562,4 +562,133 @@ class OidcJwtServiceTest < ActiveSupport::TestCase
|
|||||||
assert_includes decoded.keys, "azp", "Should include azp claim"
|
assert_includes decoded.keys, "azp", "Should include azp claim"
|
||||||
assert_equal @application.client_id, decoded["azp"], "azp should be the application's client_id"
|
assert_equal @application.client_id, decoded["azp"], "azp should be the application's client_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Scope-based claim filtering tests (OIDC Core compliance)
|
||||||
|
|
||||||
|
test "openid scope only should include minimal required claims" do
|
||||||
|
token = @service.generate_id_token(@user, @application, scopes: "openid")
|
||||||
|
|
||||||
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
|
# Required claims should always be present
|
||||||
|
assert_includes decoded.keys, "iss", "Should include issuer"
|
||||||
|
assert_includes decoded.keys, "sub", "Should include subject"
|
||||||
|
assert_includes decoded.keys, "aud", "Should include audience"
|
||||||
|
assert_includes decoded.keys, "exp", "Should include expiration"
|
||||||
|
assert_includes decoded.keys, "iat", "Should include issued at"
|
||||||
|
assert_includes decoded.keys, "azp", "Should include authorized party"
|
||||||
|
|
||||||
|
# Scope-dependent claims should NOT be present
|
||||||
|
refute_includes decoded.keys, "email", "Should not include email without email scope"
|
||||||
|
refute_includes decoded.keys, "email_verified", "Should not include email_verified without email scope"
|
||||||
|
refute_includes decoded.keys, "name", "Should not include name without profile scope"
|
||||||
|
refute_includes decoded.keys, "preferred_username", "Should not include preferred_username without profile scope"
|
||||||
|
refute_includes decoded.keys, "groups", "Should not include groups without groups scope"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "email scope should include email claims" do
|
||||||
|
token = @service.generate_id_token(@user, @application, scopes: "openid email")
|
||||||
|
|
||||||
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
|
# Email claims should be present
|
||||||
|
assert_includes decoded.keys, "email", "Should include email with email scope"
|
||||||
|
assert_includes decoded.keys, "email_verified", "Should include email_verified with email scope"
|
||||||
|
assert_equal @user.email_address, decoded["email"]
|
||||||
|
assert_equal true, decoded["email_verified"]
|
||||||
|
|
||||||
|
# Profile claims should NOT be present
|
||||||
|
refute_includes decoded.keys, "name", "Should not include name without profile scope"
|
||||||
|
refute_includes decoded.keys, "preferred_username", "Should not include preferred_username without profile scope"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "profile scope should include profile claims" do
|
||||||
|
token = @service.generate_id_token(@user, @application, scopes: "openid profile")
|
||||||
|
|
||||||
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
|
# Profile claims should be present
|
||||||
|
assert_includes decoded.keys, "name", "Should include name with profile scope"
|
||||||
|
assert_includes decoded.keys, "preferred_username", "Should include preferred_username with profile scope"
|
||||||
|
assert_equal @user.email_address, decoded["name"]
|
||||||
|
assert_equal @user.email_address, decoded["preferred_username"]
|
||||||
|
|
||||||
|
# Email claims should NOT be present
|
||||||
|
refute_includes decoded.keys, "email", "Should not include email without email scope"
|
||||||
|
refute_includes decoded.keys, "email_verified", "Should not include email_verified without email scope"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "groups scope should include groups claim" do
|
||||||
|
admin_group = groups(:admin_group)
|
||||||
|
@user.groups << admin_group unless @user.groups.include?(admin_group)
|
||||||
|
|
||||||
|
token = @service.generate_id_token(@user, @application, scopes: "openid groups")
|
||||||
|
|
||||||
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
|
# Groups claim should be present
|
||||||
|
assert_includes decoded.keys, "groups", "Should include groups with groups scope"
|
||||||
|
assert_includes decoded["groups"], "Administrators"
|
||||||
|
|
||||||
|
# Email and profile claims should NOT be present
|
||||||
|
refute_includes decoded.keys, "email", "Should not include email without email scope"
|
||||||
|
refute_includes decoded.keys, "name", "Should not include name without profile scope"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "groups scope should not include groups claim when user has no groups" do
|
||||||
|
# Ensure user has no groups
|
||||||
|
@user.groups.clear
|
||||||
|
|
||||||
|
token = @service.generate_id_token(@user, @application, scopes: "openid groups")
|
||||||
|
|
||||||
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
|
# Groups claim should not be present when user has no groups
|
||||||
|
refute_includes decoded.keys, "groups", "Should not include empty groups claim"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "multiple scopes should include all requested claims" do
|
||||||
|
admin_group = groups(:admin_group)
|
||||||
|
@user.groups << admin_group unless @user.groups.include?(admin_group)
|
||||||
|
|
||||||
|
token = @service.generate_id_token(@user, @application, scopes: "openid email profile groups")
|
||||||
|
|
||||||
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
|
# All scope-based claims should be present
|
||||||
|
assert_includes decoded.keys, "email", "Should include email"
|
||||||
|
assert_includes decoded.keys, "email_verified", "Should include email_verified"
|
||||||
|
assert_includes decoded.keys, "name", "Should include name"
|
||||||
|
assert_includes decoded.keys, "preferred_username", "Should include preferred_username"
|
||||||
|
assert_includes decoded.keys, "groups", "Should include groups"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "scope parameter should handle space-separated string" do
|
||||||
|
token = @service.generate_id_token(@user, @application, scopes: "openid email profile")
|
||||||
|
|
||||||
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
|
assert_includes decoded.keys, "email", "Should parse space-separated scopes"
|
||||||
|
assert_includes decoded.keys, "name", "Should parse space-separated scopes"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "custom claims should always be merged regardless of scopes" do
|
||||||
|
user = users(:bob)
|
||||||
|
app = applications(:another_app)
|
||||||
|
|
||||||
|
# Add user custom claim
|
||||||
|
user.update!(custom_claims: {"custom_field" => "custom_value"})
|
||||||
|
|
||||||
|
# Request only openid scope (no email, profile, or groups)
|
||||||
|
token = @service.generate_id_token(user, app, scopes: "openid")
|
||||||
|
|
||||||
|
decoded = JWT.decode(token, nil, false).first
|
||||||
|
|
||||||
|
# Custom claims should be present even with minimal scopes
|
||||||
|
assert_equal "custom_value", decoded["custom_field"], "Custom claims should be included regardless of scopes"
|
||||||
|
|
||||||
|
# Standard claims should be filtered
|
||||||
|
refute_includes decoded.keys, "email", "Should not include email without email scope"
|
||||||
|
refute_includes decoded.keys, "name", "Should not include name without profile scope"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user