Add more XML validations
This commit is contained in:
1 parent
62849e8081
commit
4fd919ccfa
3 files changed
+152
-17
No files matched your search
@@ -1045,7 +1045,6 @@ async function processRequest(
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
for (const w of parseWarnings) {
|
for (const w of parseWarnings) {
|
||||||
w.sessionContext = sessionContext;
|
w.sessionContext = sessionContext;
|
||||||
w.rpc = rpc;
|
|
||||||
logger.accessWarn(w);
|
logger.accessWarn(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+150
-14
@@ -127,7 +127,8 @@ function parameterInfoList(xml: Element): [Path, boolean, boolean][] {
|
|||||||
|
|
||||||
if (parsed == null) {
|
if (parsed == null) {
|
||||||
warnings.push({
|
warnings.push({
|
||||||
message: "Invalid writable attribute",
|
message: "Missing or invalid XML node",
|
||||||
|
element: "Writable",
|
||||||
parameter: param,
|
parameter: param,
|
||||||
});
|
});
|
||||||
parsed = false;
|
parsed = false;
|
||||||
@@ -167,7 +168,8 @@ function parameterValueList(
|
|||||||
let valueType = getValueType(valueElement.attrs);
|
let valueType = getValueType(valueElement.attrs);
|
||||||
if (!valueType) {
|
if (!valueType) {
|
||||||
warnings.push({
|
warnings.push({
|
||||||
message: "Invalid value type attribute",
|
message: "Missing or invalid XML node",
|
||||||
|
attribute: "type",
|
||||||
parameter: param,
|
parameter: param,
|
||||||
});
|
});
|
||||||
valueType = "xsd:string";
|
valueType = "xsd:string";
|
||||||
@@ -179,7 +181,8 @@ function parameterValueList(
|
|||||||
parsed = parseBool(value);
|
parsed = parseBool(value);
|
||||||
if (parsed == null) {
|
if (parsed == null) {
|
||||||
warnings.push({
|
warnings.push({
|
||||||
message: "Invalid value attribute",
|
message: "Missing or invalid XML node",
|
||||||
|
element: "Value",
|
||||||
parameter: param,
|
parameter: param,
|
||||||
});
|
});
|
||||||
parsed = value;
|
parsed = value;
|
||||||
@@ -188,7 +191,8 @@ function parameterValueList(
|
|||||||
parsed = parseInt(value);
|
parsed = parseInt(value);
|
||||||
if (isNaN(parsed)) {
|
if (isNaN(parsed)) {
|
||||||
warnings.push({
|
warnings.push({
|
||||||
message: "Invalid value attribute",
|
message: "Missing or invalid XML node",
|
||||||
|
element: "Value",
|
||||||
parameter: param,
|
parameter: param,
|
||||||
});
|
});
|
||||||
parsed = value;
|
parsed = value;
|
||||||
@@ -197,7 +201,8 @@ function parameterValueList(
|
|||||||
parsed = Date.parse(value);
|
parsed = Date.parse(value);
|
||||||
if (isNaN(parsed)) {
|
if (isNaN(parsed)) {
|
||||||
warnings.push({
|
warnings.push({
|
||||||
message: "Invalid value attribute",
|
message: "Missing or invalid XML node",
|
||||||
|
element: "Value",
|
||||||
parameter: param,
|
parameter: param,
|
||||||
});
|
});
|
||||||
parsed = value;
|
parsed = value;
|
||||||
@@ -232,7 +237,8 @@ function parameterAttributeList(xml: Element): [Path, number, string[]][] {
|
|||||||
let notification = parseInt(notificationElement.text);
|
let notification = parseInt(notificationElement.text);
|
||||||
if (isNaN(notification)) {
|
if (isNaN(notification)) {
|
||||||
warnings.push({
|
warnings.push({
|
||||||
message: "Invalid notification attribute",
|
message: "Missing or invalid XML node",
|
||||||
|
element: "Notification",
|
||||||
parameter: param,
|
parameter: param,
|
||||||
});
|
});
|
||||||
notification = 0;
|
notification = 0;
|
||||||
@@ -331,7 +337,10 @@ function SetParameterValuesResponse(xml: Element): SetParameterValuesResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(status >= 0)) {
|
if (!(status >= 0)) {
|
||||||
warnings.push({ message: "Invalid SetParameterValuesResponse status" });
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "Status",
|
||||||
|
});
|
||||||
status = 0;
|
status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,8 +401,14 @@ function AddObjectResponse(xml: Element): AddObjectResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!/^[0-9]+$/.test(instanceNumber))
|
||||||
|
throw new Error("Missing or invalid instance number");
|
||||||
|
|
||||||
if (!(status >= 0)) {
|
if (!(status >= 0)) {
|
||||||
warnings.push({ message: "Invalid AddObjectResponse status" });
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "Status",
|
||||||
|
});
|
||||||
status = 0;
|
status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,7 +439,10 @@ function DeleteObjectResponse(xml: Element): DeleteObjectResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(status >= 0)) {
|
if (!(status >= 0)) {
|
||||||
warnings.push({ message: "Invalid DeleteObjectResponse status" });
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "Status",
|
||||||
|
});
|
||||||
status = 0;
|
status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,10 +513,29 @@ function DownloadResponse(xml: Element): DownloadResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(status >= 0)) {
|
if (!(status >= 0)) {
|
||||||
warnings.push({ message: "Invalid DownloadResponse status" });
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "Status",
|
||||||
|
});
|
||||||
status = 0;
|
status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (startTime == null || isNaN(startTime)) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "StartTime",
|
||||||
|
});
|
||||||
|
startTime = Date.parse("0001-01-01T00:00:00Z");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completeTime == null || isNaN(completeTime)) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "CompleteTime",
|
||||||
|
});
|
||||||
|
completeTime = Date.parse("0001-01-01T00:00:00Z");
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "DownloadResponse",
|
name: "DownloadResponse",
|
||||||
status: status,
|
status: status,
|
||||||
@@ -537,6 +574,30 @@ function Inform(xml: Element): InformRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!deviceId || !deviceId.SerialNumber || !deviceId.OUI)
|
||||||
|
throw new Error("Missing or invalid DeviceId element");
|
||||||
|
|
||||||
|
if (!parameterList) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "ParameterList",
|
||||||
|
});
|
||||||
|
parameterList = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!evnt) {
|
||||||
|
warnings.push({ message: "Missing or invalid XML node", element: "Event" });
|
||||||
|
evnt = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (retryCount == null || isNaN(retryCount)) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "RetryCount",
|
||||||
|
});
|
||||||
|
retryCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "Inform",
|
name: "Inform",
|
||||||
parameterList: parameterList,
|
parameterList: parameterList,
|
||||||
@@ -563,7 +624,10 @@ function GetRPCMethodsResponse(methodResponse): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function TransferComplete(xml: Element): TransferCompleteRequest {
|
function TransferComplete(xml: Element): TransferCompleteRequest {
|
||||||
let commandKey, _faultStruct, startTime, completeTime;
|
let commandKey: string,
|
||||||
|
_faultStruct: FaultStruct,
|
||||||
|
startTime: number,
|
||||||
|
completeTime: number;
|
||||||
for (const c of xml.children) {
|
for (const c of xml.children) {
|
||||||
switch (c.localName) {
|
switch (c.localName) {
|
||||||
case "CommandKey":
|
case "CommandKey":
|
||||||
@@ -581,6 +645,38 @@ function TransferComplete(xml: Element): TransferCompleteRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (commandKey == null) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "CommandKey",
|
||||||
|
});
|
||||||
|
commandKey = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_faultStruct) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "FaultStruct",
|
||||||
|
});
|
||||||
|
_faultStruct = { faultCode: "0", faultString: "" };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (startTime == null || isNaN(startTime)) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "StartTime",
|
||||||
|
});
|
||||||
|
startTime = Date.parse("0001-01-01T00:00:00Z");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (completeTime == null || isNaN(completeTime)) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "CompleteTime",
|
||||||
|
});
|
||||||
|
completeTime = Date.parse("0001-01-01T00:00:00Z");
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "TransferComplete",
|
name: "TransferComplete",
|
||||||
commandKey: commandKey,
|
commandKey: commandKey,
|
||||||
@@ -606,7 +702,12 @@ function RequestDownloadResponse(): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function faultStruct(xml: Element): FaultStruct {
|
function faultStruct(xml: Element): FaultStruct {
|
||||||
let faultCode, faultString, setParameterValuesFault: SpvFault[], pn, fc, fs;
|
let faultCode: string,
|
||||||
|
faultString: string,
|
||||||
|
setParameterValuesFault: SpvFault[],
|
||||||
|
pn: string,
|
||||||
|
fc: string,
|
||||||
|
fs: string;
|
||||||
for (const c of xml.children) {
|
for (const c of xml.children) {
|
||||||
switch (c.localName) {
|
switch (c.localName) {
|
||||||
case "FaultCode":
|
case "FaultCode":
|
||||||
@@ -617,6 +718,7 @@ function faultStruct(xml: Element): FaultStruct {
|
|||||||
break;
|
break;
|
||||||
case "SetParameterValuesFault":
|
case "SetParameterValuesFault":
|
||||||
setParameterValuesFault = setParameterValuesFault || [];
|
setParameterValuesFault = setParameterValuesFault || [];
|
||||||
|
pn = fc = fs = null;
|
||||||
for (const cc of c.children) {
|
for (const cc of c.children) {
|
||||||
switch (cc.localName) {
|
switch (cc.localName) {
|
||||||
case "ParameterName":
|
case "ParameterName":
|
||||||
@@ -638,11 +740,27 @@ function faultStruct(xml: Element): FaultStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (faultCode == null) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "FaultCode",
|
||||||
|
});
|
||||||
|
faultCode = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (faultString == null) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "FaultString",
|
||||||
|
});
|
||||||
|
faultString = "";
|
||||||
|
}
|
||||||
|
|
||||||
return { faultCode, faultString, setParameterValuesFault };
|
return { faultCode, faultString, setParameterValuesFault };
|
||||||
}
|
}
|
||||||
|
|
||||||
function fault(xml: Element): CpeFault {
|
function fault(xml: Element): CpeFault {
|
||||||
let faultCode, faultString, detail;
|
let faultCode: string, faultString: string, detail: FaultStruct;
|
||||||
for (const c of xml.children) {
|
for (const c of xml.children) {
|
||||||
switch (c.localName) {
|
switch (c.localName) {
|
||||||
case "faultcode":
|
case "faultcode":
|
||||||
@@ -657,7 +775,25 @@ function fault(xml: Element): CpeFault {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { faultCode, faultString, detail };
|
if (!detail) throw new Error("Missing detail element");
|
||||||
|
|
||||||
|
if (faultCode == null) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "faultcode",
|
||||||
|
});
|
||||||
|
faultCode = "Client";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (faultString == null) {
|
||||||
|
warnings.push({
|
||||||
|
message: "Missing or invalid XML node",
|
||||||
|
element: "faultstring",
|
||||||
|
});
|
||||||
|
faultString = "CWMP fault";
|
||||||
|
}
|
||||||
|
|
||||||
|
return { faultCode, faultString, detail } as CpeFault;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function request(
|
export function request(
|
||||||
|
|||||||
+2
-2
@@ -289,8 +289,8 @@ export interface FaultStruct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface CpeFault {
|
export interface CpeFault {
|
||||||
faultCode: string;
|
faultCode: "Client" | "Server";
|
||||||
faultString: string;
|
faultString: "CWMP fault";
|
||||||
detail?: FaultStruct;
|
detail?: FaultStruct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user