Skip to content

Commit

Permalink
Support for fail-on-error for container sbom generation. Env variable…
Browse files Browse the repository at this point in the history
… to force non-strict tar extraction.

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
  • Loading branch information
prabhu committed Dec 26, 2024
1 parent f0e70a6 commit 0a08b74
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/managers/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ export function getOSPackages(src) {
}
if (osReleaseData["VERSION_ID"]) {
distro_id = `${distro_id}-${osReleaseData["VERSION_ID"]}`;
if (OS_DISTRO_ALIAS[distro_id]) {
distro_codename = OS_DISTRO_ALIAS[distro_id];
}
}
const tmpDependencies = {};
(tmpBom.dependencies || []).forEach((d) => {
Expand Down
18 changes: 17 additions & 1 deletion lib/managers/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,15 @@ export const getImage = async (fullImageName) => {
* @param entry {tar.ReadEntry} ReadEntry object from node-tar
*/
function handleAbsolutePath(entry) {
// Don't waste time with gibberish path
if (
!entry ||
!entry.path ||
entry.path.startsWith("{") ||
entry.path.includes("\n")
) {
return;
}
if (entry.path === "/" || win32.isAbsolute(entry.path)) {
entry.path = stripAbsolutePath(entry.path);
}
Expand All @@ -808,10 +817,13 @@ export const extractTar = async (fullImageName, dir, options) => {
filter: (path, entry) => {
// Some files are known to cause issues with extract
return !(
path.startsWith("{") ||
path.includes("\n") ||
path.includes("etc/machine-id") ||
path.includes("etc/gshadow") ||
path.includes("etc/shadow") ||
path.endsWith("etc/passwd") ||
path.endsWith("etc/ssl/certs") ||
path.includes("usr/lib/systemd/") ||
path.includes("usr/lib64/libdevmapper.so") ||
path.includes("usr/sbin/") ||
Expand Down Expand Up @@ -876,8 +888,12 @@ export const extractTar = async (fullImageName, dir, options) => {
* 1) TAR_ENTRY_INFO is an informative error indicating that an entry is being modified.
* 2) TAR_ENTRY_INVALID indicates that a given entry is not valid tar archive entry and will be skipped.
*/
} else if (!["TAR_ENTRY_INFO", "TAR_ENTRY_INVALID"].includes(err.code)) {
} else if (
DEBUG_MODE &&
["TAR_ENTRY_INFO", "TAR_ENTRY_INVALID"].includes(err.code)
) {
console.log(err);
return false;
} else if (DEBUG_MODE) {
console.log(err.code, "is not handled yet in extractTar method.");
}
Expand Down
2 changes: 1 addition & 1 deletion types/lib/managers/binary.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/lib/managers/docker.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0a08b74

Please sign in to comment.