
概要
JWS の署名を検証せずに JWS をデコードし、各ヘッダーをフロー変数に書き込みます。このポリシーは、JWS の署名の検証前に JWS 内のヘッダーの値がわかっている必要のある場合に、VerifyJWS ポリシーと組み合わせて使用すると非常に便利です。
JWS は添付ペイロードを持つことができ、次の形式になります。
header.payload.signature
また、JWS はペイロードを省略でき、それは分離ペイロードと呼ばれ、次の形式になります。
header..signature
DecodeJWS ポリシーは JWS のヘッダー部分のみをデコードするため、どちらの形式でも機能します。DecodeJWS ポリシーは JWS への署名に使用されたアルゴリズムにも関係なく機能します。
JWS の詳細と形式の概要については、JWS および JWT ポリシーの概要をご覧ください。
動画
JWT のデコード方法についての短い動画をご覧ください。この動画は JWT 用ですが、コンセプトの多くは JWS と同じです。
サンプル: JWS をデコードする
以下に示すポリシーでは、フロー変数 var.JWS 内の JWT をデコードします。この変数が存在し、かつ有効(デコード可能)な JWS が含まれている必要があります。このポリシーは、JWS をあらゆるフロー変数から得ることができます。
<DecodeJWS name="JWS-Decode-HS256"> <DisplayName>JWS Verify HS256</DisplayName> <Source>var.JWS</Source> </DecodeJWS>
JWS のヘッダー部分にあるヘッダーごとに、このポリシーでは次の名前のフロー変数が設定されます。
jws.policy-name.header.header-name
JWS が添付ペイロードを持っている場合は、ペイロードに jws.policy-name.header.payload
フロー変数が設定されます。分離ペイロードの場合は、payload
が空になります。このポリシーで設定される変数の全リストについては、フロー変数をご覧ください。
Decode JWS の要素リファレンス
このポリシー リファレンスでは、Decode JWS ポリシーの要素と属性について説明します。
最上位の要素に適用される属性
<DecodeJWS name="JWS" continueOnError="false" enabled="true" async="false">
次の属性は、すべてのポリシーの親要素に共通です。
属性 | 説明 | デフォルト | 要否 |
---|---|---|---|
name |
ポリシーの内部名。名前に使用できる文字は A-Z0-9._\-$ % のみです。ただし、Edge 管理 UI では、英数字以外の文字を自動的に削除するなど、追加の制限が適用されます。
必要に応じて、 |
なし | 必須 |
continueOnError |
ポリシーが失敗した場合にエラーを返すには、false に設定します。これはほとんどのポリシーで想定される動作です。
ポリシーが失敗してもフロー実行を続行するには、 |
false | 省略可 |
enabled |
ポリシーを適用するには true に設定します。
ポリシーを「turn off」するには、 |
true | 省略可 |
async | この属性は非推奨となりました。 | false | 非推奨 |
<DisplayName>
<DisplayName>Policy Display Name</DisplayName>
name 属性に加えて、管理 UI プロキシ エディタのポリシーに別の自然言語名でラベルを付けるために使います。
デフォルト | この要素を省略した場合、ポリシーの name 属性の値が使用されます。 |
要否 | 省略可 |
型 | 文字列 |
<Source>
<Source>JWS-variable</Source>
この要素が存在する場合、デコード対象の JWS が検出されるとポリシーが想定するフロー変数を指定します。
デフォルト | request.header.authorization (デフォルトに関する重要な情報については、上記の注をご覧ください)。 |
要否 | 省略可 |
型 | 文字列 |
有効な値 | Edge のフロー変数名 |
Flow variables
Upon success, the Verify JWS and Decode JWS policies set context variables according to this pattern:
jws.{policy_name}.{variable_name}
For example, if the policy name is verify-jws
, then the policy will store
the algorithm specified in the JWS to this context variable:
jws.verify-jws.header.algorithm
Variable name | Description |
---|---|
decoded.header.name |
The JSON-parsable value of a header in the payload. One variable is set for
every header in the payload. While you can also use the header.name flow variables,
this is the recommended variable to use to access a header. |
header.algorithm |
The signing algorithm used on the JWS. For example, RS256, HS384, and so on. See (Algorithm) Header Parameter for more. |
header.kid |
The Key ID, if added when the JWS was generated. See also "Using a JSON Web Key Set (JWKS)" at JWT and JWS policies overview to verify a JWS. See (Key ID) Header Parameter for more. |
header.type |
The header type value. See (Type) Header Parameter for more. |
header.name |
The value of the named header (standard or additional). One of these will be set for every additional header in the header portion of the JWS. |
header-json |
The header in JSON format. |
payload |
The JWS payload if the JWS has an attached payload. For a detached paylod, this variable is empty. |
valid |
In the case of VerifyJWS, this variable will be true when the signature is verified, and
the current time is before the token expiry, and after the token notBefore value, if they
are present. Otherwise false.
In the case of DecodeJWS, this variable is not set. |
エラー リファレンス
This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.
Runtime errors
These errors can occur when the policy executes.
Fault code | HTTP status | Occurs when |
---|---|---|
steps.jws.FailedToDecode |
401 | The policy was unable to decode the JWS. The JWS is possibly corrupted. |
steps.jws.FailedToResolveVariable |
401 | Occurs when the flow variable specified in the <Source> element of
the policy does not exist. |
steps.jws.InvalidClaim |
401 | For a missing claim or claim mismatch, or a missing header or header mismatch. |
steps.jws.InvalidJsonFormat |
401 | Invalid JSON found in the JWS header. |
steps.jws.InvalidJws |
401 | This error occurs when the JWS signature verification fails. |
steps.jws.InvalidPayload |
401 | The JWS payload is invalid. |
steps.jws.InvalidSignature |
401 | <DetachedContent> is omitted and the JWS has a detached content payload. |
steps.jws.MissingPayload |
401 | The JWS payload is missing. |
steps.jws.NoAlgorithmFoundInHeader |
401 | Occurs when the JWS omits the algorithm header. |
steps.jws.UnknownException |
401 | An unknown exception occurred. |
Deployment errors
These errors can occur when you deploy a proxy containing this policy.
Error name | Occurs when |
---|---|
InvalidAlgorithm |
The only valid values are: RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512, HS256, HS384, HS512. |
|
Other possible deployment errors. |
Fault variables
These variables are set when a runtime error occurs. For more information, see What you need to know about policy errors.
Variables | Where | Example |
---|---|---|
fault.name="fault_name" |
fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code. | fault.name Matches "TokenExpired" |
JWS.failed |
All JWS policies set the same variable in the case of a failure. | jws.JWS-Policy.failed = true |
Example error response
For error handling, the best practice is to trap the errorcode
part of the error
response. Do not rely on the text in the faultstring
, because it could change.
Example fault rule
<FaultRules> <FaultRule name="JWS Policy Errors"> <Step> <Name>JavaScript-1</Name> <Condition>(fault.name Matches "TokenExpired")</Condition> </Step> <Condition>JWS.failed=true</Condition> </FaultRule> </FaultRules>