Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions artifactory-oidc/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,31 @@ runs:
;;
maven)
mkdir -p ~/.m2/

# actions/setup-java (run before this action) may have already written
# ~/.m2/settings.xml with its own <servers> (e.g. GitHub Packages
# credentials), <profiles> (custom repositories, GPG passphrase), and
# <activeProfiles>. We overwrite this file, so extract those blocks
# first and splice them back in — otherwise we'd silently drop
# credentials/config the calling workflow depends on.
EXISTING_SERVERS=""
EXISTING_PROFILES=""
EXISTING_ACTIVE_PROFILES=""
if [ -f ~/.m2/settings.xml ]; then
echo "::notice::Found existing ~/.m2/settings.xml (e.g. from actions/setup-java) — merging its <servers>, <profiles>, and <activeProfiles>"
EXISTING_SERVERS=$(python3 "$GITHUB_ACTION_PATH/extract-xml-children.py" ~/.m2/settings.xml servers)
EXISTING_PROFILES=$(python3 "$GITHUB_ACTION_PATH/extract-xml-children.py" ~/.m2/settings.xml profiles)
EXISTING_ACTIVE_PROFILES=$(python3 "$GITHUB_ACTION_PATH/extract-xml-children.py" ~/.m2/settings.xml activeProfiles)
fi
Comment thread
kostasniktas marked this conversation as resolved.

# Pass vars explicitly into envsubst's environment so the child process can see them.
ART_USERNAME="$ART_USERNAME" \
ART_TOKEN="$ART_TOKEN" \
ARTIFACTORY_URL="$ARTIFACTORY_URL" \
REGISTRY_PATH="$REGISTRY_PATH" \
EXISTING_SERVERS="$EXISTING_SERVERS" \
EXISTING_PROFILES="$EXISTING_PROFILES" \
EXISTING_ACTIVE_PROFILES="$EXISTING_ACTIVE_PROFILES" \
envsubst < "$GITHUB_ACTION_PATH/maven-settings.xml.tmpl" > ~/.m2/settings.xml
echo "::notice::Maven configured to use Artifactory registry (${REGISTRY_PATH})"
;;
Expand Down
37 changes: 37 additions & 0 deletions artifactory-oidc/extract-xml-children.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""Print the child elements of the first <tag> found in an XML file, ignoring
namespaces, as XML fragments (bare of namespace declarations). Used in place
of `xmllint --xpath "//*[local-name()='TAG']/*"`, which isn't installed on
GitHub-hosted runners by default.

Usage: extract-xml-children.py <file> <tag>
"""
import sys
import xml.etree.ElementTree as ET


def strip_ns(el: ET.Element) -> ET.Element:
"""
Remove the namespace from the default {namespace_namespace}tag_name representation

Instead of {http://maven....}server, we'd get server
"""
el.tag = el.tag.rsplit("}", 1)[-1]
for child in el:
strip_ns(child)
return el


def main() -> None:
path, tag = sys.argv[1], sys.argv[2]
root = ET.parse(path).getroot()

@semgrep-code-twilio semgrep-code-twilio Bot Sep 2, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The native Python xml library is vulnerable to XML External Entity (XXE) attacks. These attacks can leak confidential data and "XML bombs" can cause denial of service. Do not use this library to parse untrusted input. Instead the Python documentation recommends using defusedxml.

🥳 Removed in commit 2e26cfc 🥳

for el in root.iter():
if el.tag.rsplit("}", 1)[-1] == tag:
for child in list(el):
sys.stdout.write(ET.tostring(strip_ns(child), encoding="unicode"))
return
pass # No matching parent element found — print nothing.


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions artifactory-oidc/maven-settings.xml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<username>${ART_USERNAME}</username>
<password>${ART_TOKEN}</password>
</server>
${EXISTING_SERVERS}
</servers>
<mirrors>
<mirror>
Expand All @@ -17,4 +18,10 @@
<url>${ARTIFACTORY_URL}/artifactory/${REGISTRY_PATH}</url>
</mirror>
</mirrors>
<profiles>
${EXISTING_PROFILES}
</profiles>
<activeProfiles>
${EXISTING_ACTIVE_PROFILES}
</activeProfiles>
</settings>
Loading