Skip to content

fix(policy): read system policy values with their stored AppConfig type - #9554

Open
no84by wants to merge 1 commit into
LibreSign:mainfrom
no84by:fix/appconfig-typed-values
Open

no84by wants to merge 1 commit into
LibreSign:mainfrom
no84by:fix/appconfig-typed-values

Conversation

@no84by

@no84by no84by commented Nov 18, 2026

Copy link
Copy Markdown

Resolves: #9456

Summary

Since Nextcloud 35, AppConfig logs a warning before it throws AppConfigTypeConflictException. PolicySource::readSystemValue() relied on that exception: it requested the type of the policy default first and fell back to other typed getters on conflict. For values that older releases stored with another type, every policy resolution logged one or two warnings, which is why they appear on every page load.

Observed on an affected 15.0.12 / Nextcloud 35.0.3 instance, counted from its log:

Warning Count
libresign/identification_documents is stored as boolean but was requested as array 33
libresign/identification_documents is stored as boolean but was requested as string 33
libresign/groups_request_sign is stored as array but was requested as string 14

The issue also lists add_footer stored as boolean, which goes through the same path.

The existing repair steps (Version19001Date20261022200000, Version19004Date20261027180000) only fix the type metadata of values that already hold JSON, so a legacy boolean stays as it is, and the reader keeps producing the warnings.

This change looks up the stored type with IAppConfig::getValueType() first and reads the value with that type, so no conflicting getter is called. The values handed to the policy normalizers are the same as with the previous fallback chain:

  • a stored array for a string policy is passed on JSON encoded;
  • a stored boolean for a string policy (add_footer) is passed on as boolean;
  • a stored scalar other than a string for an array policy (identification_documents) still resolves to the policy default;
  • values stored with the expected type, or as mixed, are read exactly as before.

Writers are unchanged: saveSystemPolicy() already rewrites the key with the normalized type, so saving the policy once in the admin settings also migrates the stored type.

How to test

  1. On Nextcloud 35 or later, store legacy typed values:
    occ config:app:set libresign identification_documents --value=true --type=boolean
    occ config:app:set libresign add_footer --value=true --type=boolean
    occ config:app:set libresign groups_request_sign --value='["admin"]' --type=array
  2. Load any page, or resolve the three system policies through PolicySource::loadSystemPolicy().
  3. Before: nextcloud.log gets five is stored as ... but was requested as ... warnings per resolution (two each for identification_documents and add_footer, one for groups_request_sign). After: none, and the resolved values are identical.

Validation evidence

  • Focused regression/acceptance test
  • Relevant lint/type/static-analysis checks
  • Broader suite required by the changed surface
  • CI reviewed

What ran (PHP 8.5, Nextcloud server master 36.0.0 dev, SQLite):

  • PolicySourceTest::testLoadSystemPolicyReadsLegacyTypedValueWithItsStoredType (new, four data sets). InMemoryAppConfig now records reads that request another type than the stored one, as Nextcloud logs them. On main three data sets fail with the exact warnings from the issue; with the fix all pass.
  • phpunit --testsuite unit: 4997 tests OK (one unrelated PHP 8.5 deprecation in FileService).
  • Integration: Version19001Date20261022200000Test, Version19004Date20261027180000Test, PolicySourceRuleCountTest: 37 tests OK.
  • The "How to test" steps above against an installed server: 5 warnings before, 0 after, same resolved values.
  • php-cs-fixer --dry-run on the changed files: clean. psalm on PolicySource.php: no errors.

API / Back-end changes

  • PolicySource::readSystemValue() reads system policy values with their stored AppConfig type instead of probing typed getters.
  • Unit and/or integration tests added or updated
  • Authorization and negative paths checked when applicable
  • Capabilities updated when applicable
  • Documentation updated when applicable
  • API documentation regenerated via composer openapi when necessary

Tasks

  • Read with the stored type
  • Regression test for identification_documents, add_footer and groups_request_sign

Checklist

  • I have read and followed the contribution guide.
  • The diff does not contain unrelated refactors or generated changes.
  • Commits follow Conventional Commits where applicable.
  • All commits include the required DCO sign-off.

AI (if applicable)

  • The content of this PR was partially or fully generated using AI

Older releases stored some policy values with another AppConfig type than
the policy API writes today, for example identification_documents and
add_footer as boolean or groups_request_sign as array.

PolicySource::readSystemValue() requested the type of the policy default
first and fell back to other getters on AppConfigTypeConflictException.
Nextcloud logs a warning before throwing that exception, so every policy
resolution on such an instance logged one or two "is stored as X but was
requested as Y" warnings.

Look up the stored type first and read the value with it. The values handed
to the policy normalizers stay the same as with the previous fallback chain.

Resolves: LibreSign#9456
Signed-off-by: no84by <50858621+no84by@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

NC 35: "Config value libresign/... is stored as X but was requested as Y" on every page load

1 participant