Skip to content

Restrict SOURCE_PDF access to admins across activity and document endpoints#38

Merged
milljoniaer merged 3 commits intomainfrom
copilot/exclude-source-pdf-for-non-admins
Mar 27, 2026
Merged

Restrict SOURCE_PDF access to admins across activity and document endpoints#38
milljoniaer merged 3 commits intomainfrom
copilot/exclude-source-pdf-for-non-admins

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

SOURCE_PDF documents were accessible to non-admin users via activity GET responses and the document info endpoint. This PR enforces admin-only access at both layers.

Changes

Activity GET responses

  • ActivityController passes isAdmin(authentication) as includeSourcePdf flag for both GET /api/activities/ and GET /api/activities/{id}
  • ActivityService.mapToResponse() filters out SOURCE_PDF documents when includeSourcePdf=false

DocumentsController — download endpoint

  • enforceDownloadAccess() throws AccessDeniedException for non-admins attempting to download SOURCE_PDF documents

DocumentsController — info endpoint (new protection)

  • GET /api/documents/{documentId}/info now also calls enforceDownloadAccess(), preventing metadata leakage (filename, size, confidence score) to non-admins
  • Added Authentication parameter and @SecurityRequirement annotation; re-throws AccessDeniedException to bypass the generic catch (Exception e) → 404 handler
// info endpoint now mirrors the download endpoint's access control
PDFDocument document = pdfService.getPdfDocument(documentId);
enforceDownloadAccess(document, authentication); // blocks non-admins for SOURCE_PDF

Tests

  • Added mapToResponseIncludesSourcePdfDocumentsForAdmin to verify admins (includeSourcePdf=true) do receive SOURCE_PDF entries in the documents list

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • jfrog-prod-use1-shared-virginia-main.s3.amazonaws.com
    • Triggering command: /usr/lib/jvm/temurin-21-jdk-amd64/bin/java /usr/lib/jvm/temurin-21-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15/bin/m2.conf -Dmaven.home=/home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15 -Dlibrary.jansi.path=/home/REDACTED/.m2/wrapper/dists/apache-maven-3.9.11/a2d47e15/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/LEARN-Hub/LEARN-Hub/server org.codehaus.plexus.classworlds.launcher.Launcher clean compile -q (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Dfile.encoding=UTF-8 -Xms256M -Xss8M -Djdk.util.zip.disableZip64ExtraFieldValidation=true -Dsun.misc.unsafe.memory.access=allow --add-opens java.base/sun.reflect.annotation=ALL-UNNAMED -Xmx14579m -classpath /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/java/tools/semmle-extractor-java.jar:/opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/java/tools/lombok-javac-extend.jar com.semmle.extractor.java.JavaExtractor --jdk-version 17 --javac-args @@@/tmp/codeql-scratch-21fe057196e5a270/dbs/java/log/ext/javac.args earnhub/documentgit earnhub/document-c earnhub/documentcore.quotePath=false earnhub/documentdiff (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Exclude source pdf for non-admin users from activity response Restrict SOURCE_PDF access to admins across activity and document endpoints Mar 26, 2026
Copilot AI requested a review from milljoniaer March 26, 2026 13:08
@milljoniaer milljoniaer marked this pull request as ready for review March 27, 2026 09:46
@milljoniaer milljoniaer merged commit 5d5480f into main Mar 27, 2026
2 checks passed
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.

2 participants