fix(plist): read XML plists containing a __proto__ key
The `plist` XML decoder throws on the legal dictionary key `__proto__`
(its CVE-2022-22912 guard). An app whose XML Info.plist held such an
entry could not be opened at all ("app has no readable
CFBundleExecutable"), and entitlements, XML keyed archives, and
Interface Builder plists failed the same way. On the plutil JSON route,
validation silently dropped the key from `inspect_plist` results.
Decode XML plists through a shared reader that substitutes such keys
before the decoder runs, then omits and counts those entries.
`inspect_plist` and `inspect_keyed_archive` report the omission as a
limitation instead of failing or dropping it silently.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
507e8b3c7b
commit
a08be51e9f
@@ -8,7 +8,6 @@ import { observeNativeUi } from "./NativeUiObservation.js";
|
||||
import { dirname, isAbsolute, resolve } from "node:path";
|
||||
import { open, realpath, stat } from "node:fs/promises";
|
||||
|
||||
import { parse as parseXmlPlist } from "plist";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
@@ -35,6 +34,7 @@ import { BinaryTargetError } from "../domain/configurationErrors.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
|
||||
import { parseXmlPropertyList } from "../domain/propertyListKeys.js";
|
||||
import {
|
||||
demangleSwiftSchema,
|
||||
inspectPlistSchema,
|
||||
@@ -645,7 +645,7 @@ const parseEntitlements = (output: string): JsonValue | null => {
|
||||
const end = output.lastIndexOf("</plist>");
|
||||
if (start < 0 || end < start) return null;
|
||||
return jsonValueSchema.parse(
|
||||
parseXmlPlist(output.slice(start, end + "</plist>".length)),
|
||||
parseXmlPropertyList(output.slice(start, end + "</plist>".length)).value,
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { parse as parseXmlPlist } from "plist";
|
||||
import { z } from "zod";
|
||||
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
@@ -7,6 +6,11 @@ import {
|
||||
projectPlistValue,
|
||||
type ProjectedPlistValue,
|
||||
} from "../../domain/plistValue.js";
|
||||
import {
|
||||
omitPrototypeKeys,
|
||||
omittedPrototypeKeysLimitation,
|
||||
parseXmlPropertyList,
|
||||
} from "../../domain/propertyListKeys.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
|
||||
const plistObject = z.record(z.string(), z.unknown());
|
||||
@@ -99,9 +103,9 @@ export const parsePlistJson = (
|
||||
ambiguousNumberCount += 1;
|
||||
return item;
|
||||
};
|
||||
let value: unknown;
|
||||
let decoded: ReturnType<typeof omitPrototypeKeys>;
|
||||
try {
|
||||
value = decodePlistJson(output, classify);
|
||||
decoded = omitPrototypeKeys(decodePlistJson(output, classify));
|
||||
} catch (cause: unknown) {
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
@@ -111,10 +115,14 @@ export const parsePlistJson = (
|
||||
),
|
||||
);
|
||||
}
|
||||
const { value } = decoded;
|
||||
return ok({
|
||||
value,
|
||||
bundle: projectPlistBundle(value),
|
||||
limitations: numberLimitations(exactIntegerCount, ambiguousNumberCount),
|
||||
limitations: [
|
||||
...numberLimitations(exactIntegerCount, ambiguousNumberCount),
|
||||
...prototypeKeyLimitations(decoded.omittedPrototypeKeys),
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
@@ -126,8 +134,11 @@ export const parsePlistXml = (
|
||||
output: string,
|
||||
): Result<ParsedPlist, AnalysisOutputError> => {
|
||||
let projected: ProjectedPlistValue;
|
||||
let omittedPrototypeKeys: number;
|
||||
try {
|
||||
projected = projectPlistValue(parseXmlPlist(output));
|
||||
const decoded = parseXmlPropertyList(output);
|
||||
omittedPrototypeKeys = decoded.omittedPrototypeKeys;
|
||||
projected = projectPlistValue(decoded.value);
|
||||
} catch (cause: unknown) {
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
@@ -168,6 +179,7 @@ export const parsePlistXml = (
|
||||
`${String(projected.unknownRealCount)} non-finite real value(s) are reported as { "$plist_type": "real", "value": null } because the XML decoder does not distinguish NaN from infinity.`,
|
||||
]),
|
||||
...numberLimitations(exactIntegerCount, ambiguousNumberCount),
|
||||
...prototypeKeyLimitations(omittedPrototypeKeys),
|
||||
],
|
||||
});
|
||||
};
|
||||
@@ -201,6 +213,9 @@ const xmlNumberLiterals = (xml: string): XmlNumberLiterals => {
|
||||
return { integers, reals };
|
||||
};
|
||||
|
||||
const prototypeKeyLimitations = (count: number): string[] =>
|
||||
count === 0 ? [] : [omittedPrototypeKeysLimitation(count)];
|
||||
|
||||
const numberLimitations = (
|
||||
exactIntegerCount: number,
|
||||
ambiguousNumberCount: number,
|
||||
|
||||
Reference in New Issue
Block a user