Package com.helger.http.csp
Class AbstractCSPSourceList<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>>
java.lang.Object
com.helger.http.csp.AbstractCSPSourceList<IMPLTYPE>
- Type Parameters:
IMPLTYPE- Implementation type
- All Implemented Interfaces:
com.helger.base.trait.IGenericImplTrait<IMPLTYPE>
- Direct Known Subclasses:
CSPSourceList
@NotThreadSafe
public abstract class AbstractCSPSourceList<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>>
extends Object
implements com.helger.base.trait.IGenericImplTrait<IMPLTYPE>
A source list to be used in a CSP directive (
CSPDirective). It's just a convenient way to
build a CSP directive value.- Author:
- Philip Helger
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor creating an empty CSP source list. -
Method Summary
Modifier and TypeMethodDescription@NonNull IMPLTYPEaddHash(@NonNull com.helger.security.messagedigest.EMessageDigestAlgorithm eMDAlgo, byte @NonNull @Nonempty [] aHashValue) Add the provided nonce value.@NonNull IMPLTYPEaddHash(@NonNull com.helger.security.messagedigest.EMessageDigestAlgorithm eMDAlgo, @NonNull String sHashBase64Value) Add the provided Base64 encoded hash value.@NonNull IMPLTYPEaddHost(@NonNull com.helger.url.ISimpleURL aHost) Add a host@NonNull IMPLTYPEAdd a host@NonNull IMPLTYPEsource expression 'none' represents an empty set of URIs@NonNull IMPLTYPEIf this expression is included in a directive controlling scripts or styles, and the directive causes the browser to block any inline scripts, inline styles, or event handler attributes, then the violation report that the browser generates will contain a sample property containing the first 40 characters of the blocked resource.@NonNull IMPLTYPEsource expression 'self' represents the set of URIs which are in the same origin as the protected resource@NonNull IMPLTYPEThe 'strict-dynamic' keyword makes the trust conferred on a script by a nonce or a hash extend to scripts that this script dynamically loads, for example by creating new <script> tags using Document.createElement() and then inserting them into the document using Node.appendChild().@NonNull IMPLTYPEBy default, if a CSP contains a default-src or a script-src directive, then JavaScript functions which evaluate their arguments as JavaScript are disabled.@NonNull IMPLTYPEsource expression 'unsafe-inline' represents content supplied inline in the resource itself@NonNull IMPLTYPEaddMimeType(@NonNull com.helger.mime.IMimeType aMimeType) Add a MIME type (for plugin-types)@NonNull IMPLTYPEaddNonce(byte @NonNull @Nonempty [] aNonceValue) Add the provided nonce value.@NonNull IMPLTYPEAdd the provided Base64 encoded nonce value.@NonNull IMPLTYPEAdd a schemeboolean@NonNull StringintinthashCode()@NonNull StringtoString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.base.trait.IGenericImplTrait
thisAsT
-
Field Details
-
KEYWORD_NONE
- See Also:
-
KEYWORD_REPORT_SAMPLE
- See Also:
-
KEYWORD_SELF
- See Also:
-
KEYWORD_STRICT_DYNAMIC
- See Also:
-
KEYWORD_UNSAFE_INLINE
- See Also:
-
KEYWORD_UNSAFE_EVAL
- See Also:
-
NONCE_PREFIX
- See Also:
-
NONCE_SUFFIX
- See Also:
-
HASH_PREFIX
- See Also:
-
HASH_SUFFIX
- See Also:
-
-
Constructor Details
-
AbstractCSPSourceList
public AbstractCSPSourceList()Default constructor creating an empty CSP source list.
-
-
Method Details
-
getExpressionCount
@Nonnegative public int getExpressionCount()- Returns:
- The number of source expressions in this list. Always ≥ 0.
-
addScheme
Add a scheme- Parameters:
sScheme- Scheme in the formatscheme ":"- Returns:
- this
-
addHost
Add a host- Parameters:
aHost- Host to add. Must be a valid URL.- Returns:
- this
-
addHost
Add a host- Parameters:
sHost- Host to add. Must be a valid URL or a star prefixed version.- Returns:
- this
-
addMimeType
Add a MIME type (for plugin-types)- Parameters:
aMimeType- MIME type to add. May not benull.- Returns:
- this
-
addKeywordNone
source expression 'none' represents an empty set of URIs- Returns:
- this
-
addKeywordReportSample
If this expression is included in a directive controlling scripts or styles, and the directive causes the browser to block any inline scripts, inline styles, or event handler attributes, then the violation report that the browser generates will contain a sample property containing the first 40 characters of the blocked resource.- Returns:
- this
-
addKeywordSelf
source expression 'self' represents the set of URIs which are in the same origin as the protected resource- Returns:
- this
-
addKeywordStrictDynamic
The 'strict-dynamic' keyword makes the trust conferred on a script by a nonce or a hash extend to scripts that this script dynamically loads, for example by creating new <script> tags using Document.createElement() and then inserting them into the document using Node.appendChild().- Returns:
- this
-
addKeywordUnsafeEval
By default, if a CSP contains a default-src or a script-src directive, then JavaScript functions which evaluate their arguments as JavaScript are disabled. This includes "eval()", the code argument to "setTimeout()", or the "Function()" constructor.- Returns:
- this
-
addKeywordUnsafeInline
source expression 'unsafe-inline' represents content supplied inline in the resource itself- Returns:
- this
-
addNonce
Add the provided nonce value. The "\'nonce-"<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>> andNONCE_SUFFIXare added automatically. The byte array is automatically Bas64 encoded.- Parameters:
aNonceValue- The plain nonce bytes. May not benull.- Returns:
- this for chaining
-
addNonce
Add the provided Base64 encoded nonce value. The "\'nonce-"<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>> andNONCE_SUFFIXare added automatically.- Parameters:
sNonceBase64Value- The Base64 encoded nonce value- Returns:
- this for chaining
-
addHash
public @NonNull IMPLTYPE addHash(@NonNull com.helger.security.messagedigest.EMessageDigestAlgorithm eMDAlgo, byte @NonNull @Nonempty [] aHashValue) Add the provided nonce value. The "\'"<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>> andHASH_SUFFIXare added automatically. The byte array is automatically Bas64 encoded!- Parameters:
eMDAlgo- The message digest algorithm used. May onlyEMessageDigestAlgorithm.SHA_256,EMessageDigestAlgorithm.SHA_384orEMessageDigestAlgorithm.SHA_512. May not benull.aHashValue- The plain hash digest value. May not benull.- Returns:
- this for chaining
-
addHash
public @NonNull IMPLTYPE addHash(@NonNull com.helger.security.messagedigest.EMessageDigestAlgorithm eMDAlgo, @NonNull String sHashBase64Value) Add the provided Base64 encoded hash value. The "\'"<IMPLTYPE extends AbstractCSPSourceList<IMPLTYPE>> andHASH_SUFFIXare added automatically.- Parameters:
eMDAlgo- The message digest algorithm used. May onlyEMessageDigestAlgorithm.SHA_256,EMessageDigestAlgorithm.SHA_384orEMessageDigestAlgorithm.SHA_512. May not benull.sHashBase64Value- The Base64 encoded hash value- Returns:
- this for chaining
-
getAsString
- Returns:
- The whole source list as a single string, separated by a blank char.
-
equals
-
hashCode
public int hashCode() -
toString
-