Repository navigation
Fix registry security review findings (infrastructure#68) on gbif-common-ws 2.1.4 - #876
Conversation
Finding 1 and 2 of gbif/infrastructure#68. - DELETE /doi/{prefix}/{suffix} had no authorization: any caller, including anonymous ones, could request the deletion of any DOI. - POST/PUT /doi let any logged-in user register or rewrite the metadata of any DOI. The only callers are occurrence-ws/event-ws (app keys) and the download workflow (admin user), so all three now require REGISTRY_ADMIN or APP. Metadata is also validated before it is saved, so invalid metadata is no longer persisted.
Finding 3 of gbif/infrastructure#68. The editor, GrSciColl editor, legacy, pre-check and not-found filters matched anchored regexes against the raw request URI and let the request through when nothing matched. Spring MVC decodes the URI, drops path parameters and ignores a trailing slash, so e.g. PUT /dataset/{key}/, an encoded dash or ;a=b reached the handler without the per-entity check. GrSciColl patterns also rejected uppercase UUIDs, which UUID.fromString accepts. The filters now use RequestPathUtils.normalizedPath: the path within the application, decoded, without path parameters, repeated or trailing slashes. GrSciColl and not-found patterns accept uppercase hex.
Finding 4 of gbif/infrastructure#68. - The Authorization header and decoded user:password were logged, and returned in the 401 body when the user was not a UUID (any normal user hitting a legacy endpoint). Neither is logged or returned now. - Invalid Base64 or organisationKey gave 500, now 400. - Unknown key, wrong organization password and wrong installation password gave different messages, revealing which keys exist. All are now 401 "Invalid credentials". - Passwords are compared in constant time. - Organization shared tokens are generated with SecureRandom instead of java.util.Random. Tokens are still stored in plain text: the ?op=password reminder e-mails them, so hashing them needs that feature retired first.
- Requests without credentials are no longer authenticated (gbif/informatics#53), so anyRequest().authenticated() rejected every anonymous request, including public GETs. The URL level now uses permitAll(); endpoints were and stay secured by method security, which now rejects anonymous callers for real. - IdentityFilter no longer catches exceptions thrown further down the chain (gbif/informatics#62). The registry filters throw WebApplicationException to reject requests, so a new WebApplicationExceptionFilter right after IdentityFilter answers them with their status and message.
Finding 10 of gbif/infrastructure#68. JwtRequestFilter set 401 on an invalid or expired JWT but continued the chain, so the request ran as anonymous and endpoints without @secured still did their work. It now answers 401 and stops. Token revocation, an absolute lifetime and invalidation on password change are not part of this change.
…cks callback Finding 5 of gbif/infrastructure#68. - GET /registry/organisation/{key}?op=password needs no authentication and returned the primary contact's e-mail address. The reminder is still sent, but the response no longer contains the address. - The JSONP callback is written as JavaScript in the response; anything but a plain function name is now rejected with 400.
Finding 17 of gbif/infrastructure#68. - GET /organization/{key}/endorsement/user/{user} told anyone whether any user could endorse for a node. Non-admins can now only ask about themselves (registry-console asks for the logged-in user). - Async requests failing with 503 returned the internal exception message; it is logged and a generic message is returned. 400 messages are kept, they describe the invalid parameter.
Finding 15 of gbif/infrastructure#68. - Exported cells starting with = + - @ were run as formulas by spreadsheet applications (dataset search, GrSciColl and download exports). They are now prefixed with a quote, except numbers and phone numbers. - The descriptor suggestion download built Content-Disposition by concatenating the user supplied title, which could break out of the quotes. It is now built with ContentDisposition. Contact details in public GrSciColl exports are unchanged.
Part of finding 13 of gbif/infrastructure#68. - GET /grscicoll/{collection|institution}/batch/{key} and its resultFile were open to anyone, with sequential keys, and the result file contains contacts. Only the user who created the batch and admins can read them. - The extension of an uploaded descriptor suggestion file was taken from the client file name, which could contain path separators or e.g. .html. Only .csv, .tsv and .txt are kept; anything else is stored as .csv. Anonymous suggestions, their upload size and the e-mails they trigger are unchanged.
Part of finding 16 of gbif/infrastructure#68. GET /dataset/{key}/document and /dataset/metadata/{key}/document return the XML uploaded by publishers as application/xml. A browser opening one could run an XHTML script in it on the API origin. These responses now carry Content-Security-Policy: default-src 'none'; sandbox (nosniff was already sent). They still display in browsers. The XXE posture of the external metadata and phylogeny parsers is not checked here.
Since gbif-common-ws 2.1.4 the Authentication argument of a request without credentials is null instead of an anonymous token. The scheme checks treat null as 403, so /user/login without credentials answered 403. The user is now checked first, which answers 401 as before.
The test fixture built GBIF signatures by hand with the old scheme. It now sends and signs x-gbif-date, the canonical URL with its query string, the content type as sent and the Content-MD5 of the exact body (it used to hash the JSON body serialized a second time).
Part of findings 3 and 9 of gbif/infrastructure#68. The legacy register/update/delete endpoints had no method security: only LegacyAuthorizationFilter, which recognises them by path, authenticated the IPT. A path it did not recognise, e.g. DELETE /registry/service/, reached the handler without credentials (deleteAllDatasetEndpoints). They now require IPT_ROLE, which the legacy authentication carries.
Finding 8 of gbif/infrastructure#68. PUT/DELETE /organization/{key}/endorsement were checked by the editor filter against rights on the organization or its node, so an editor of the organization itself could endorse it. Endorsement is a node decision: like userAllowedToEndorseOrganization, non-admins now need rights on the endorsing node.
Part of finding 19 of gbif/infrastructure#68. DbConfiguration, DataCiteConfiguration and DirectoryConfiguration printed the database password, DataCite password and app secret in toString(), which the CLI services log at startup (e.g. VocabularySynchronizerService). They are masked now.
…users Part of finding 12 of gbif/infrastructure#68. - Password hashes were compared with equalsIgnoreCase, although their alphabet is case sensitive (Drupal itself compares them exactly). They are now compared exactly and in constant time. - Key based confirmations, password reset/change and e-mail change looked the user up with getByKey, which returns deleted users. They now ignore deleted users. Challenge codes still do not expire and the hashing is still Drupal 7 SHA-512.
…n-ws 2.1.4 gbif-common-ws 2.1.4 checks the Content-MD5 of GBIF signed requests against the buffered body. Signed uploads (dataset documents, descriptor suggestions) were rejected with 401: - DebugFilter, first in the chain, called getParameterMap() only to log a debug line. For multipart and form bodies that makes the container parse and consume the body before HttpServletRequestWrapperFilter buffers it, so the buffered body was empty. It is removed. - Without it the body is buffered, but then the container finds no multipart parts or form parameters in the consumed input stream. The new FormBodyRequestWrapperFilter wraps multipart and form requests without buffering, which HttpServletRequestWrapperFilter leaves as they are; their Content-MD5 is not verified, as before 2.1.4. This is better handled in gbif-common-ws itself (do not buffer these content types in GbifHttpServletRequestWrapper).
Part of finding 20 of gbif/infrastructure#68: avro 1.11.3 (CVE-2024-47561) and parquet-avro 1.12.3 (CVE-2025-30065). parquet 1.17.0 is built with avro 1.11.5. woodstox-core-asl, zookeeper and hadoop are unchanged.
Part of finding 9 of gbif/infrastructure#68. The UUIDs were compared with !=, so the change of installation was logged for every update; the log also had the old and new keys swapped.
…NAPSHOT gbif-api 2.4.30 changed the checklistKey of the GrSciColl search requests from String to UUID: - the services convert it to String for the mapper params, falling back to defaultChecklistKey as before; - the checklistKey query parameter is parsed as a UUID, an invalid value is an IllegalArgumentException; - tests use UUIDs, random ones where the key only had to match nothing. download-query-tools 2.0.13-SNAPSHOT is needed with this gbif-api: 2.0.12 fails to build the human readable query and falls back to the predicate as JSON in download DOI descriptions (DownloadConverterTest).
2b6893e to
7807b7b
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Signed form bodies can bypass integrity verification, and CSV/TSV exports remain vulnerable to formula injection; anonymous authentication and permission prechecks also have unresolved errors.
6 open issues
GBIF signatures skip body validation for form and multipart requests · New CSV exports leave formula-injection values and headers unneutralized · New Anonymous prechecks dereference a missing authentication principal · New Number exemption allows spreadsheet formulas and unsafe phone formats · New Permission precheck bypasses the node-rights check · New Debug logging dereferences null authentication before returning 401 · New
What changed in this PR
Addresses registry security-review findings and adapts the registry to the authentication and request-signing changes in gbif-common-ws 2.1.4.
Changes:
- Tightens authorization for DOI writes, legacy IPT operations, endorsements, and batch access.
- Hardens credential handling, user-account updates, exports, metadata responses, and error messages.
- Updates dependencies, adopts UUID checklist keys, and adds regression tests and revised signing fixtures.
The snapshot dependencies still need released versions before merging, as noted in the PR description.
| File | Description |
|---|---|
registry-ws/src/test/java/org/gbif/registry/ws/export/CsvWriterTest.java |
Tests formula neutralization and preserved values. |
registry-ws/src/main/java/org/gbif/registry/ws/resources/UserResource.java |
Reorders authentication and scheme checks. |
registry-ws/src/main/java/org/gbif/registry/ws/resources/OrganizationResource.java |
Secures password generation and endorsement checks. |
registry-ws/src/main/java/org/gbif/registry/ws/resources/legacy/LegacyOrganizationResource.java |
Validates callbacks and hides reminder email addresses. |
registry-ws/src/main/java/org/gbif/registry/ws/resources/legacy/LegacyEndpointResource.java |
Requires the IPT role for writes. |
registry-ws/src/main/java/org/gbif/registry/ws/resources/legacy/LegacyDatasetResource.java |
Adds role checks to legacy dataset writes. |
registry-ws/src/main/java/org/gbif/registry/ws/resources/legacy/IptResource.java |
Adds role checks and corrects UUID comparison. |
registry-ws/src/main/java/org/gbif/registry/ws/resources/DoiInteractionResource.java |
Restricts writes and validates metadata before persistence. |
registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/CollectionResource.java |
Safely constructs download disposition headers. |
registry-ws/src/main/java/org/gbif/registry/ws/resources/collections/BaseCollectionEntityResource.java |
Restricts batch and result-file access. |
registry-ws/src/main/java/org/gbif/registry/ws/provider/CollectionDescriptorsSearchRequestHandlerMethodArgumentResolver.java |
Parses checklist keys as UUIDs. |
registry-ws/src/main/java/org/gbif/registry/ws/export/CsvWriter.java |
Adds spreadsheet-formula neutralization. |
registry-ws/src/main/java/org/gbif/registry/ws/exception/AsyncExceptionHandler.java |
Logs internal errors and returns generic messages. |
registry-service/src/main/java/org/gbif/registry/service/collections/descriptors/DescriptorChangeSuggestionServiceImpl.java |
Limits generated filenames to allowed extensions. |
registry-service/src/main/java/org/gbif/registry/service/collections/descriptors/DefaultDescriptorService.java |
Adapts descriptor queries to UUID checklist keys. |
registry-service/src/main/java/org/gbif/registry/service/collections/CollectionsSearchService.java |
Adapts collection queries to UUID checklist keys. |
registry-security/src/test/java/org/gbif/registry/security/util/RequestPathUtilsTest.java |
Tests request-path normalization. |
registry-security/src/test/java/org/gbif/registry/security/LegacyAuthorizationServiceImplTest.java |
Tests legacy authentication and sanitized failures. |
registry-security/src/test/java/org/gbif/registry/security/grscicoll/GrSciCollEditorAuthorizationFilterTest.java |
Tests uppercase and trailing-slash authorization paths. |
registry-security/src/test/java/org/gbif/registry/security/EditorAuthorizationFilterTest.java |
Tests encoded and parameterized authorization paths. |
registry-security/src/main/java/org/gbif/registry/security/WebApplicationExceptionFilter.java |
Converts filter exceptions into HTTP responses. |
registry-security/src/main/java/org/gbif/registry/security/util/RequestPathUtils.java |
Centralizes authorization-path normalization. |
registry-security/src/main/java/org/gbif/registry/security/ResourceNotFoundRequestFilter.java |
Uses normalized paths and uppercase UUID matching. |
registry-security/src/main/java/org/gbif/registry/security/precheck/AuthPreCheckCreationRequestFilter.java |
Normalizes permission-precheck paths. |
registry-security/src/main/java/org/gbif/registry/security/LegacyAuthorizationServiceImpl.java |
Sanitizes failures and compares credentials securely. |
registry-security/src/main/java/org/gbif/registry/security/LegacyAuthorizationFilter.java |
Uses normalized paths for legacy authorization. |
registry-security/src/main/java/org/gbif/registry/security/jwt/JwtRequestFilter.java |
Stops requests with invalid JWTs. |
registry-security/src/main/java/org/gbif/registry/security/grscicoll/GrSciCollEditorAuthorizationFilter.java |
Normalizes paths and accepts uppercase UUIDs. |
registry-security/src/main/java/org/gbif/registry/security/FormBodyRequestWrapperFilter.java |
Preserves servlet form and multipart parsing. |
registry-security/src/main/java/org/gbif/registry/security/EditorAuthorizationFilter.java |
Applies authorization to normalized paths. |
registry-security/src/main/java/org/gbif/registry/security/DebugFilter.java |
Removes eager form-parameter parsing. |
registry-security/src/main/java/org/gbif/registry/security/config/WebSecurityConfigurer.java |
Updates filter ordering, anonymous routing, and metadata headers. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/UserManagementIT.java |
Tests deleted-user mutation restrictions. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/security/jwt/JwtIT.java |
Expects unauthorized responses for invalid tokens. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/OrganizationCreationIT.java |
Tests endorsement rights and eligibility-query restrictions. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/legacy/LegacyOrganizationResourceIT.java |
Tests reminder privacy and callback rejection. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/legacy/LegacyEndpointResourceIT.java |
Tests rejection of anonymous endpoint deletion. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/fixtures/RequestTestFixture.java |
Implements the revised request-signing scheme. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/DoiRegistrationIT.java |
Tests DOI write authorization. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/DatasetIT.java |
Tests metadata-document content security headers. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/service/descriptors/DescriptorsServiceIT.java |
Updates descriptor tests for UUID checklist keys. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/service/CollectionsSearchIT.java |
Updates collection-search tests for UUID checklist keys. |
registry-integration-tests/src/test/java/org/gbif/registry/ws/it/collections/resource/BaseCollectionEntityResourceIT.java |
Tests protected batch and result-file reads. |
registry-identity/src/test/java/org/gbif/registry/identity/util/RegistryPasswordEncoderTest.java |
Tests exact password-hash matching. |
registry-identity/src/main/java/org/gbif/registry/identity/util/RegistryPasswordEncoder.java |
Uses null-safe, constant-time hash comparison. |
registry-identity/src/main/java/org/gbif/registry/identity/service/IdentityServiceImpl.java |
Excludes deleted users from account changes. |
registry-cli/src/main/java/org/gbif/registry/cli/common/DirectoryConfiguration.java |
Masks application secrets in string output. |
registry-cli/src/main/java/org/gbif/registry/cli/common/DbConfiguration.java |
Masks database passwords in string output. |
registry-cli/src/main/java/org/gbif/registry/cli/common/DataCiteConfiguration.java |
Masks DataCite passwords in string output. |
pom.xml |
Updates dependencies and adds snapshot repository access. |
Review effort: Balanced
| if (isFormBody(request) && !(request instanceof GbifHttpServletRequestWrapper)) { | ||
| filterChain.doFilter(new GbifHttpServletRequestWrapper(request, false), response); |
There was a problem hiding this comment.
Fixed in gbif-common-ws (gbif/gbif-common-ws#33, c15712c12): the wrapper now buffers application/x-www-form-urlencoded bodies and serves their parameters from the buffer, so their Content-MD5 is verified. FormBodyRequestWrapperFilter is removed here (d0ff1d4). Multipart bodies are still not buffered, so the container can parse their parts; their Content-MD5 is not verified, as before 2.1.4. That is documented in the gbif-common-ws changelog.
| String cleaned = DELIMETERS_MATCH_PATTERN.matcher(value).replaceAll(" "); | ||
| if (FORMULA_START_PATTERN.matcher(cleaned).find() | ||
| && !NUMBER_LIKE_PATTERN.matcher(cleaned).matches()) { |
There was a problem hiding this comment.
Fixed in 7e742de: formulas are now neutralised by the CSV encoder (FormulaNeutralisingEncoder), so every cell is covered, including headers and columns without a processor (codes, identifiers, alternative codes, descriptor verbatim headers). Map keys are unchanged.
| // anonymous since gbif-common-ws 2.1.4, .authenticated() would reject them on public endpoints | ||
| .authorizeHttpRequests(auth -> auth | ||
| .anyRequest().authenticated() | ||
| .anyRequest().permitAll() |
There was a problem hiding this comment.
Fixed in d773e9c: without a user the precheck filter leaves the body unchanged, so the next filters reject the request. AuthPreCheckInterceptor answers 403 for a null authentication instead of throwing a NullPointerException.
| // numbers and phone numbers, e.g. -12.5 or +45 35 32 14 70, cannot be harmful formulas | ||
| private static final Pattern NUMBER_LIKE_PATTERN = Pattern.compile("^[+-]?[0-9 ().-]+$"); |
There was a problem hiding this comment.
Fixed in 7e742de: only plain numbers (-12.5) and phone numbers made of digits and spaces (+45 35 32 14 70) are kept. -(1), -12-5 and +1-202-555-0144 are written as text.
| if (!canEndorse(organizationKey)) { | ||
| return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); | ||
| } |
There was a problem hiding this comment.
Fixed in a0021fa: EditorAuthorizationFilter checks rights on the endorsing node for PUT/DELETE /organization/{key}/endorsement (allowedToEndorseOrganization), so the precheck gives the same answer as the request itself.
| // the user shall be authenticated using basic auth. scheme only. | ||
| ensureNotGbifScheme(authentication); | ||
| ensureUserSetInSecurityContext(authentication); | ||
| ensureNotGbifScheme(authentication); |
There was a problem hiding this comment.
Fixed in 4f51ed9: the user check now runs before the logging. Covered by UserIT.testBasicAuthNoCredentials.
?checkPermissionsOnly=true stops before the controller, so the node check of
PUT/DELETE /organization/{key}/endorsement in OrganizationResource did not
run and the editor filter accepted rights on the organization itself. The
filter now checks rights on the endorsing node for these paths.
…Exception Requests without credentials reach the precheck filter and interceptor since the security chain permits them. The filter no longer builds a body without a user, leaving the request to the next filters, and the interceptor answers 403.
The debug logging dereferenced the missing authentication before the user check.
Code, identifier and alternative code columns and descriptor verbatim headers skipped CleanStringProcessor. Formulas are now neutralised by the CSV encoder, so every cell and header is covered. Only plain numbers and phone numbers of digits and spaces are kept: -(1), -12-5 or +1-202-555-0144 would be calculated.
…torAnnotatedMethodsTest
… bodies gbif-common-ws (gbif/gbif-common-ws#33) now reads the parameters of buffered form bodies from the buffer, so their Content-MD5 is verified, and does not buffer multipart bodies.
bbd836f to
d0ff1d4
Compare
…ationService stub
…line feeds - reject anonymous tokens in ensureUserSetInSecurityContext and DOI generation - an invalid Base64 Basic header is not an IPT validation request - IdentityServiceImpl.update ignores deleted users - neutralise cells starting with a line feed - unit tests for WebApplicationExceptionFilter
|
Follow-up to an external review of this PR. Each finding was checked against the code; fixes are in db878de. Fixed
Not changed
|


Fixes from the registry security review (gbif/infrastructure#68), on top of the gbif-common-ws security fixes in gbif/gbif-common-ws#33 (
2.1.4-PR-33-SNAPSHOT). One commit per finding; most have tests.Depends on gbif/gbif-common-ws#33: switch to the released 2.1.4 before merging.
Also upgrades gbif-api to 2.4.30-SNAPSHOT and download-query-tools to 2.0.13-SNAPSHOT (last commit):
checklistKeyof the GrSciColl search requests is now a UUID; download-query-tools 2.0.12 cannot build the human readable query with this gbif-api. Switch both to releases before merging.Changes needed by gbif-common-ws 2.1.4
anyRequest().permitAll().authenticated()rejected every anonymous request, including public GETs. Endpoints stay secured by method security.WebApplicationExceptionFilterafterIdentityFilterIdentityFilterno longer catches exceptions from later filters (gbif/informatics#62); the registry filters throwWebApplicationExceptionto reject requests.DebugFilterremovedDebugFilterread the parameters first, which emptied the body. Form parameters are read from the buffered body and multipart bodies are not buffered by gbif-common-ws (gbif/gbif-common-ws#33), so form Content-MD5 is verified; multipart Content-MD5 is not, as before 2.1.4./userendpoints check the user before the schemeAuthenticationargument is now null without credentials; the scheme check answered 403 instead of 401.x-gbif-date, canonical URL with query, content type as sent, MD5 of the exact body.Findings fixed
DELETE/POST/PUT /doirequireREGISTRY_ADMINorAPP(callers: occurrence-ws/event-ws with app keys, downloads with an admin user). Metadata is validated before it is saved.IPT_ROLE.SecureRandom.?op=passwordresponse no longer contains the contact e-mail; JSONP callback must be a function name.?checkPermissionsOnly=true.!=on UUIDs in IPT dataset updates..csv,.tsv,.txt.Content-Dispositionbuilt withContentDisposition.Content-Security-Policy: default-src 'none'; sandbox.toString().Please review
appkeys.adminImpersonationconfigured (Review comments in the registry #55, warnings only by default) and every GBIF request signer updated to the new signature scheme.hbase-site.xml), 20 (woodstox, zookeeper, hadoop), 21 (CORS, ShedLock, OAI transformer; page and facet sizes are already capped).Testing
mvn verifywith-Dappkeys.testfilepointing at a keys file containinggbif.app.it2(the repo'sappkeys-test.propertieslacks it, so ~230 client-mode ITs fail without it, ondevtoo): unit tests all pass; integration tests 908 run, 0 failures, 34 skipped. 3 registry-cli ITs could not run locally for lack of theregistry-cli-it.*settings properties.