Skip to content

Add security and context filter for REST api - #595

Open
Slartibartfass2 wants to merge 22 commits into
developfrom
feat/583-feature-add-security-and-context-filter-for-rest-api
Open

Add security and context filter for REST api#595
Slartibartfass2 wants to merge 22 commits into
developfrom
feat/583-feature-add-security-and-context-filter-for-rest-api

Conversation

@Slartibartfass2

@Slartibartfass2 Slartibartfass2 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Closes #583

What I have made

This is the baseline for the REST API. Now clients can register, log in, and so on...
I added an integration test that verifies that the whole workflow works.

Checklist

Either tick or cross out the items that do not apply (using ~~example text~~) and give a reason why the item does not apply.

Author

  • I have updated the documentation accordingly and commented my code
    • [ ] I have updated AGENTS.md if the changes affect project structure, commands, tooling, or conventions
  • I have manually tested my changes
  • I have added tests that prove my fix is effective or that my feature works

Reviewer

  • I have checked the changes against the requirements

@Slartibartfass2 Slartibartfass2 self-assigned this Aug 13, 2026
@Slartibartfass2 Slartibartfass2 linked an issue Aug 13, 2026 that may be closed by this pull request
1 task
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

Code Coverage

Overall Project 98.23% 🍏

There is no coverage information present for the Files changed

@gitguardian

gitguardian Bot commented Aug 13, 2026

Copy link
Copy Markdown

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
24483668 Triggered Generic Password d7e524a src/test/kotlin/se/uulm/snowballr/backend/rest/AuthWorkflowIntegrationTest.kt View secret
36073591 Triggered Generic Password d7e524a src/test/kotlin/se/uulm/snowballr/backend/rest/AuthWorkflowIntegrationTest.kt View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@Slartibartfass2
Slartibartfass2 force-pushed the feat/583-feature-add-security-and-context-filter-for-rest-api branch 2 times, most recently from 964a4c2 to ff0ab99 Compare August 13, 2026 21:11
@Slartibartfass2
Slartibartfass2 requested a review from mowi12 August 13, 2026 21:35
@Slartibartfass2
Slartibartfass2 force-pushed the feat/583-feature-add-security-and-context-filter-for-rest-api branch from c7b47fc to 16a25a3 Compare August 13, 2026 23:21
@Slartibartfass2
Slartibartfass2 force-pushed the feat/583-feature-add-security-and-context-filter-for-rest-api branch 4 times, most recently from 267f00c to 5864cf1 Compare August 17, 2026 21:01
Slartibartfass2 and others added 17 commits August 19, 2026 15:57
writeQueuedCookies ran before filterChain.doFilter, so cookies queued
by handlers during the request (e.g. login, logout) were never
written to the response - only pre-emptive refresh/clear cookies
queued during authentication were flushed.
Drives register, verify-email, login, status, change-password, and
logout through MockMvc and the actual security filter chain, rather
than calling the service layer directly, so cookie handling on the
wire is exercised the same way a real client would use it.
Both endpoints were caught by anyRequest().authenticated(), so
/auth/status could never report UNAUTHENTICATED and /auth/logout
could never clear cookies once both tokens had expired.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…requests

SameSite=Strict blocks classic cross-site CSRF but still permits
requests from a sibling subdomain, which is same-site. Requiring a
custom header as defense-in-depth closes that gap, since forged
cross-origin form/fetch requests cannot set one without triggering a
CORS preflight.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Cookies queued by pre-emptive token refresh (or refresh-failure
clearing) were only written in the finally block after the handler
ran, so a handler streaming a large enough body to auto-flush the
output buffer silently dropped them, since Set-Cookie is a no-op on
an already-committed response. Flush them immediately instead, and
re-flush only cookies the handler itself changed afterward.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Only /actuator/health is exposed today, but the wildcard sat above
anyRequest().authenticated(), so exposing more endpoints later (e.g.
/actuator/env, /actuator/heapdump) would have made them anonymously
reachable without anyone touching the security config.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Matches the constructor-injection convention used by every other
service/manager in the codebase and avoids exposing the injected
service as public API on the controller bean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Matches the explicit binding annotations used by every other handler
in this controller instead of relying on implicit simple-type param
resolution.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Slartibartfass2 and others added 5 commits August 19, 2026 15:58
…akage

Switches the Docker healthcheck from grpc-health-probe to Spring Boot
actuator on port 8090, replacing gRPC health with HTTP health now that
Spring is the process entrypoint.

This exposed a latent bug that made the REST server unreachable:
shadowJar's default duplicatesStrategy (EXCLUDE) silently dropped
nearly all Spring Boot autoconfiguration metadata, since several
dependency jars ship META-INF/spring.factories and
META-INF/spring/*.imports at the same path. Without
TomcatServletWebServerAutoConfiguration surviving the merge, the app
booted as a plain (non-web) ApplicationContext and never bound port
8090 at all. Fixed by setting duplicatesStrategy = INCLUDE and
merging/appending the affected resource files instead of picking one
arbitrarily.

The healthcheck itself uses wget --spider rather than curl: curl was
only ever needed for pycurl's build (libcurl/curl-dev) and isn't
installed by default, while wget is already present via BusyBox in the
eclipse-temurin alpine base, so no extra package is needed. It also
drops a `grep "status":"UP"` step, since Spring Boot Actuator already
maps health status to HTTP status codes by default (200 for UP, 503
otherwise) — wget's own exit code is sufficient.

Verified with a full docker compose build/up against the real .env and
database: actuator/health returns 200 and the container reaches
Docker's healthy state using the wget-based check.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Slartibartfass2
Slartibartfass2 force-pushed the feat/583-feature-add-security-and-context-filter-for-rest-api branch from 5864cf1 to 77298b6 Compare August 19, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add security and context filter for REST API

1 participant