Skip to content

Commit

Permalink
Warn and remove long imported mdui:Logo elements; initial threshold 5…
Browse files Browse the repository at this point in the history
…0000
  • Loading branch information
iay committed Mar 23, 2020
1 parent 876b708 commit 041a185
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mdx/common-beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,22 @@
<property name="elementName" value="UIInfo"/>
</bean>

<!--
strip_mdui_logo_length
Filter out mdui:Logo elements whose text content is
longer than a threshold value. Add a warning to the
entity when this is done.
-->
<bean id="strip_mdui_logo_length" parent="mda.XSLTransformationStage"
p:XSLResource="classpath:strip-mdui-logo-length.xsl">
<property name="transformParameters">
<map>
<entry key="maxLength" value="${mdui.logo.length.remove:50000}"/>
</map>
</property>
</bean>

<!--
*****************************************************
*** ***
Expand Down Expand Up @@ -1193,12 +1209,18 @@
</property>
</bean>

<!--
Stages that modify metadata come first, so that
anything they remove is not checked later.
-->
<ref bean="cleanImport"/>
<ref bean="wrapX509Certificates"/>
<ref bean="stripAAMDUI"/>
<ref bean="stripMDUILogoHttp"/>
<ref bean="trimImportElementWhitespace"/>
<ref bean="stripEmptyExtensions"/>
<ref bean="strip_mdui_logo_length"/>

<ref bean="checkSchemas"/>
<ref bean="CHECK_std"/>
<ref bean="check_dup_display"/>
Expand Down
74 changes: 74 additions & 0 deletions mdx/strip-mdui-logo-length.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
strip-mdui-logo-length.xsl
Filters out mdui:Logo elements with lengths longer than a
provided threshold, and warns that this has been done.
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
xmlns:mdui="urn:oasis:names:tc:SAML:metadata:ui"
xmlns:mdxURL="xalan://uk.ac.sdss.xalan.md.URLchecker"
xmlns:set="http://exslt.org/sets"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:oasis:names:tc:SAML:2.0:metadata">

<!--
Common support functions.
-->
<xsl:import href="_rules/check_framework.xsl"/>

<!--
maxLength
This parameter determines the maximum allowable mdui:Logo length
before taking action.
-->
<xsl:param name="maxLength"/>

<!-- Force UTF-8 encoding for the output. -->
<xsl:output omit-xml-declaration="no" method="xml" encoding="UTF-8" indent="yes"/>

<!--
Match mdui:Logo elements whose string length is greater than the
threshold value; issue a warning for them.
Template match expressions can't include parameter references, so
match all mdui:Logo elements then dig in with a conditional.
-->
<xsl:template match="mdui:Logo">
<xsl:choose>
<xsl:when test="string-length(.) > $maxLength">
<xsl:call-template name="warning">
<xsl:with-param name="m">
<xsl:text>removed mdui:Logo with long contents: </xsl:text>
<xsl:value-of select="string-length(.)"/>
<xsl:text> > </xsl:text>
<xsl:value-of select="$maxLength"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!--By default, copy text blocks, comments and attributes unchanged.-->
<xsl:template match="text()|comment()|@*">
<xsl:copy/>
</xsl:template>

<!-- Copy all elements from the input to the output, along with their attributes and contents. -->
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 041a185

Please sign in to comment.