Commit Graph

46 Commits

Author SHA1 Message Date
Manuel Raynaud
6b1d47b80d (marketing) create a celery task to create a new contact
To ease the use of this module, we added a shared task which a wrapper
arount the configured backend and will only call the
create_or_update_contact in a celery task.
2025-12-08 15:03:18 +01:00
Manuel Raynaud
609251233a (marketing) implement brevo backend
Brevo is the first real backend we have to implement. The init method is
reposible to configure it.
2025-12-08 15:03:18 +01:00
Manuel Raynaud
48094c2eb8 (marketing) create tooling to help backend initialization
Like we did for the malware_detection module, we want helpers allowing
use to instantiate a backend without knowing in the code how to do it,
just importing a module and the marketing service is ready to be used.
2025-12-08 15:03:18 +01:00
Manuel Raynaud
f230d027ef (malware) save file hash in detection record and callback
The file hash is a crucial info. We save it in database if a record
exists but also transmit it to the callback in the error_info.
2025-12-04 16:10:15 +01:00
Manuel Raynaud
3bdfdf2b16 ♻️(malware) log filehash when a submission fail
We want to log the file has when a submission fail in order to aggregate
all this logs to send them to JCOP.
2025-12-02 09:31:29 +01:00
Manuel Raynaud
b0b90be8fe (malware) add management command to reschedule processing
We want to reschedule processing task when they are older than 3 days.
A settings is used to modify this delay. The current backend is
instanciated and it is the backend responsability to determine if it
should reschedule it or not.
2025-12-02 09:31:29 +01:00
Manuel Raynaud
519f58ea8a (malware) allow a malware detection backend to reschedule a task
For multiple reasons a task can be blocked in processing task. We wanto
to allow a backend to reschedule a blocked task.
2025-12-02 09:31:29 +01:00
Manuel Raynaud
3d86ec7e4e (malware) save backend used in a malware analysis task
For later use we wan't to know the backend used for a given task
2025-12-02 09:31:29 +01:00
Manuel Raynaud
a91ad0009e (malware) keep traces of failed malware analysis tasks
We want to keep in the database the failed tasks with the reason why
they failed. The idea is to take a decision later on what to do for
tasks reaching a max retries for example.
2025-12-02 09:31:29 +01:00
Quentin BEY
2e9ad45f30 (resource-server) fix EC key test
For some reason, this test was false but working. It does not
work anymore with recent version of jose lib so we fix it.
2025-11-21 16:41:25 +01:00
Quentin BEY
3fe817189b ♻️(resource-server) make token introspection earlier
The base implementation from Mozilla let the backend in charge
of making the introspection (probably to stay generic), but
in LaSuite project we will always perform introspection when
acting as resource server.

To improve domain consistency and "payload" access to other part
of the code, we chose to make the introspection earlier in the
authentication process.

Note the introspection payload, does not contain much information,
in our current implementation we need it to contain at least the
user's `sub``.
2025-11-21 16:41:25 +01:00
jbpenrath
a9e2daa979 👔(oidc) consider urls as refreshable no matter the HTTP method
Currently, only `GET` method as considered as refreshable url as it could
be weird to return a redirect response for other kind of HTTP methods.
On our side, we assume to be always in a XHR context so we don't want
to be bothered by redirects and in case the session has expired
we returned a 401 status. So we can safely ignore the request HTTP method
to check if the url is refreshable.
2025-11-05 10:32:04 +01:00
Hsiaoming Yang
f1a357b9b8 (joserfc) remove pyjwt from tests
Use joserfc everywhere.
2025-11-04 13:49:35 +01:00
Manuel Raynaud
ef11d21bdb (backend) extract reach and roles choices
We extract the reach and roles choices and all utils function from the
docs project. We will use them in other projects.
2025-10-27 11:01:05 +01:00
Quentin BEY
61136971e8 🐛(oidc) do not allow user sub update when set
When a user's sub is defined, we don't want to allow any update
because it would break to many related data.

This fix is required since we changed the way user data is
updated in 7409ea8c6e
2025-10-24 15:04:30 +02:00
Thomas Recouvreux
7409ea8c6e 🐛(oidc) fix update_user when User.sub is nullable
User model `sub` field may be nullable in certain projects, we make sure
the user is correctly updated in this case by using the User.id during
update.

Example of User.sub being nullable: in case of multi authentication
backends.
Example of project using a nullable User.sub: docs (lasuite).
2025-10-24 14:17:02 +02:00
Ghislain LE MEUR
5491204d17 🐛(oidc) fix session persistence with Redis backend for OIDC flows
Fixes session persistence issues with OIDC flows, particularly when
using a Redis backend, and strengthens OIDC security.

Key changes include:

**Session Persistence (Redis)**:
- Forcing immediate session saving (`request.session.modified = True`
  and `request.session.save()`) in OIDC logout and authentication
  views. This is crucial for cache-based session backends like Redis
  to ensure OIDC states are persisted before redirects.
- Simplified session creation by calling `session.create()` BEFORE
  `super().get()` instead of after (more logical flow).
- Removed unnecessary state merging logic that was over-engineering.

**Security Enhancements**:
- Added CSRF protection by validating the state parameter even during
  silent login failures (error=login_required).
- State is now preserved (not deleted) on error=login_required to
  allow the SSO provider to send a subsequent callback with the
  authorization code using the same state.
- Enforced strict state parameter validation during silent login
  failures (`error=login_required`), raising `SuspiciousOperation`
  if state is missing or invalid.
- Graceful handling of logout callbacks without state parameter to
  accommodate SSO providers sending preflight requests.

**Testing**:
- Added comprehensive tests for silent login security validation
  (invalid state, missing state, valid state).
- Updated test expectations to match new behavior where states are
  preserved during silent login failures.
- Added test for logout callback without state parameter.

These changes enhance both the reliability and security of OIDC
login and logout flows, especially in distributed environments
using Redis for session management.
2025-10-24 13:35:54 +02:00
Quentin BEY
b5d1027787 (oidc) add backend logout endpoint
This endpoint can be called by the IdP to kill all the user
sessions.

In order to allow to kill only one session, we need to store the
session ID when login from IdP...
2025-10-24 13:27:39 +02:00
Manuel Raynaud
e08b8c7d50 (drf) implement monitored scope throttling class
We want to monitor the usage of a scope throttle. We want to know when a
throttle fails in order to determine if the rate is accurate or not.
To allow custom monitoring, a callback can be use. For example you can
capture a message in sentry instead logging a warning.
2025-09-05 14:32:02 +02:00
Manuel Raynaud
501e94d0fc (malware_detection) management command launching pending analysis
We added a management command to force to launch pending analysis. This
management command can be run periodically in a cron in order to have a
pending analysis blocked and never run.
2025-07-22 17:03:54 +02:00
Manuel Raynaud
1169eda8eb (malware_detection) limit simultaneous files analysis for jcop
For the JCOP backend we need to limit the number of simultaneous files
analysis. The number of simultaneous analysis must be configurable, by
default we limit it to 15.
To achieve this, we store in a table the pending analysis and a new
analysis is triggered at the end of a previous one.
2025-07-22 17:03:54 +02:00
Manuel Raynaud
5ba2dea9c7 🐛(tests) fix test_project app to be usable with management command
The test_project app had missing configuration blocking usage of the
django admin management commands. We need to use them for generating
migrations.
2025-07-22 17:03:54 +02:00
Quentin BEY
dbd4e8f25c 🚨(joserfc) fix deprecation warning
RSAKey must be imported from `joserfc.jwk`.
2025-07-09 14:39:31 +02:00
Quentin BEY
53f1adaf67 🐛(resource-server) allow aud & iss JWE headers
The new implementation in Proconnect uses the panva
node-oidc-provider lib which add two extra headers.
We allow them but not rely on them.
2025-07-09 14:39:25 +02:00
Quentin BEY
04c184fc0d 💩(tests) monkeypatch the InMemoryFileNode
Django < 5.2 does not properly store the name.
2025-06-06 17:40:58 +02:00
Quentin BEY
69b7c34ada (jose) fix test after new version of jose lib
Fix after release of joserfc v1.1.0
2025-06-06 17:32:36 +02:00
Quentin BEY
b5383fbc53 🐛(oidc-rs) fix non base 64 authentication token
When the token is a JWT, the base64 testing was failing when calling the
resource server endpoint.
2025-05-20 18:41:56 +02:00
soyouzpanda
06dc5aa836 (configuration) add configuration Value to support file path in env
This supports use of environment variables that either reference
a value or a path to file containing the value. This is useful for
secrets, to avoid the secret to be in a world-readable environment
file.
2025-05-20 15:51:24 +02:00
Manuel Raynaud
88816d1de9 ♻️(malware_detection) retry getting analyse result sooner
Once an analyse started, we were wiating 30 seconds to try having a
first time the result and then the retry delay was always equal to 30
seconds between every retries. JCOP ask us to reduce this waiting time
to few seconds, an analyse job should start quickly and depending the
file size the result will be available in few seconds.
2025-05-20 15:38:59 +02:00
Manuel Raynaud
453018a732 (malware_detection) add a module malware_detection
In many projects we need a solution to analyse file to detect malware in
them. We want to do this job once here and then reuse it in all the
projects.
2025-05-06 18:35:37 +02:00
Quentin BEY
f9e9e60e12 🐛(oidc) use the OIDC_USER_SUB_FIELD when needed
The code allows to not use `sub` to store the sub data of the user, but
some part of the code, where still using the hardcoded `sub` attribute.
2025-05-05 14:28:02 +02:00
Quentin BEY
2f4dfa08bf 🔊(oidc) improve resource server log inactive user
The claims validation was making an error when the user is inactive
making debug session quite complex. This does not change the behavior
but add more explicit logs.
2025-05-05 12:39:17 +02:00
Quentin BEY
653b4f7ae7 🐛(oidc) fix resource server client
The client was always requesting for a JWT introspection reponse even if
we wanted a JSON. This commit fixes the issue by hard linking the
resource server client to the resource server backend we use.
2025-05-05 09:46:06 +02:00
Quentin BEY
21714305d4 🐛(oidc) fix user info endpoint format auto
The content type may contain more information than just the content
type, like the charset.
2025-04-23 10:16:03 +02:00
Quentin BEY
477d532291 🎨(tests) use the pytest fixture for dj settings
Make the use of the pytest fixture uniform across our code.
2025-04-11 14:04:37 +02:00
Quentin BEY
aabe212501 💥(oidc) normalize setting names
The first implementation was trying to keep names used across our
projects but we better make things clean before broad adoption of the
library.
2025-04-11 14:04:32 +02:00
Quentin BEY
0474fd060f 🐛(oidc) do not allow empty sub claim
Introduced in version 0.0.3: the sub claim was check for presence but
not check if properly filled.
2025-04-10 14:23:50 +02:00
Quentin BEY
dda74f38ae (oidc) allow silent login authentication
This provides the backend tools to manage silent login.
2025-04-10 12:30:09 +02:00
Quentin BEY
88f9cbf6c1 🐛(oidc) add "is new" information to post action
Some post user "get or create" actions need to adapt whether the user
was created or not.
2025-04-10 12:30:09 +02:00
Quentin BEY
2098a7db29 (oidc) add essential claims check setting
This allow to enforce claims presence in OIDC response by simply setting
a parameter.
2025-04-09 16:07:33 +02:00
Quentin BEY
83ecd7884d (oidc) allow JSON format in user info endpoint
In some cases, the OIDC identity provider does not allow to use JWT in
userinfo response, we want to be able to explicitely disable it.
2025-04-09 15:15:53 +02:00
Quentin BEY
5be1dbb1c5 🐛(oidc-rs) do not check iss in introspection
When using introspection with a `token_introspection` claim, we don't
need to check the issuer twice (because the `iss` inside the
`token_introspection` is not mandatory and the issuer is already check
in the containing JWT).
2025-04-07 12:00:12 +02:00
Quentin BEY
47930a205e (oidc) add refresh token tools
This provides a way to to refresh the OIDC access token.

The OIDC token will be used to request data to a resource server.
This code is highly related to
mozilla/mozilla-django-oidc#377

The refresh token is encrypted in the session.
2025-04-03 17:09:54 +02:00
Quentin BEY
e8a56a2960 (oidc) add the authentication backends
This provides:
 - the OIDC authentication backend we use on our project to allow
   connection via OIDC
 - the OIDC authentication backend for URLs to expose via Resource
   Server
2025-04-03 17:03:23 +02:00
Quentin BEY
c0d76bb20c (tools) extract domain from email address
This provides a standard way to extract the domain from an email
address. This is not used in the package but it could be used in several
projects.
2025-04-02 11:37:59 +02:00
Quentin BEY
f049940ddb 🎉(build) bootstrap library folders
Add initial project structure with tests and configuration files:
 - ruff for format and linting
 - uv with hatch for packaging
2025-03-29 08:55:01 +01:00