Skip to content

[5.0] Misc fix backport - #809

Merged
fstagni merged 16 commits into
DIRACGrid:rel-v5r0from
sfayer:fix_miscv5
Oct 26, 2026
Merged

fstagni merged 16 commits into
DIRACGrid:rel-v5r0from
sfayer:fix_miscv5

Conversation

@sfayer

@sfayer sfayer commented Oct 26, 2026

Copy link
Copy Markdown
Member

This is a backport of #808 + various other minor fixes that have been applied recently on 6.0; all the same sort of stuff.

Regards,
Simon

BEGINRELEASENOTES
FIX: Collection of minor webapp fixes
ENDRELEASENOTES

chaen and others added 16 commits October 25, 2026 22:08
Replace Subprocess.shellCall with Subprocess.systemCall using argument
lists instead of shell-interpolated strings. This prevents potential
command injection if file paths or passwords contain shell metacharacters.

Also changed -password to -passin/-passout which are the correct OpenSSL
flags (the old flags worked but were deprecated/ambiguous).
The web_hostAction and web_componentAction methods allow restarting DIRAC
components, reverting software, and updating software on any host. These
are destructive operations that should require elevated privileges.

Add @authorization decorator requiring CSAdministrator or
ServiceAdministrator property for these methods instead of allowing any
authenticated user.
The root.tpl template has autoescape disabled ({% autoescape None %}),
so the welcome file content is rendered as raw HTML. If an attacker can
modify the welcome file, they could inject malicious scripts.

Fix:
- Use bleach.clean() to sanitize HTML, allowing only safe tags (p, br, a,
  img, headings, lists, emphasis) and limited attributes
- Fall back to xhtml_escape if bleach is not available
- Use tempfile.mkdtemp() instead of predictable time.time()+random()
  for secure temporary directory creation
- Validate archivePath in second pass to ensure it's within the system
  temp directory, preventing path traversal attacks like reading /etc/passwd
- Use os.path.realpath() to resolve symlinks before validation
- Add error handling for file cleanup operations
- Use json_encode() for JavaScript context escaping instead of raw
  template interpolation which allowed XSS via access_token and next params
- Add __validateNextURL() to prevent open redirect attacks by rejecting
  URLs with dangerous schemes (javascript:, data:) or external hosts
- Add samesite="Lax" to all cookies to mitigate CSRF attacks
…ification

Using jwt.decode with verify_signature=False is a dangerous pattern that
can be accidentally copied to security-critical code. Replace with
jwt.get_unverified_claims() which explicitly indicates the intent to
read token payload for display purposes only without verification.

The tokens come from the trusted TokenManagerClient backend and are only
displayed to the user, not used for authorization decisions.
- Use jwt.decode with verify_signature=False: jwt.get_unverified_claims
  does not exist in PyJWT (caught by pylint E1101)
- Rename Properties.CSAdministrator/ServiceAdministrator to
  Properties.CS_ADMINISTRATOR/SERVICE_ADMINISTRATOR, as fixed upstream
  in DIRACGrid#807 (caught by pylint E1101 against DIRAC rel-v8r0)
- Apply black/prettier formatting to satisfy pre-commit
@fstagni
fstagni merged commit 121a493 into DIRACGrid:rel-v5r0 Oct 26, 2026
5 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.

3 participants