fix(tests): serve.mjs post-bind wildcard check reads the 'IPv6' family of server.address(); report-compare checks the type before opening (a FIFO or device is never opened) and again on the handle
This commit is contained in:
1 parent
d7d99b4766
commit
854d988c07
2 files changed
+13
-4
No files matched your search
@@ -118,15 +118,20 @@ impl Files for Disk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read(&self, path: &str) -> Result<Vec<u8>, FileFailure> {
|
fn read(&self, path: &str) -> Result<Vec<u8>, FileFailure> {
|
||||||
// One open, then the checks on that handle: the path is resolved once.
|
// The type is checked before the open (a FIFO or a device is never opened), then
|
||||||
let file = fs::File::open(path).map_err(|e| failure_of(&e))?;
|
// again on the handle (the path is not swapped for a directory in between).
|
||||||
let meta = file.metadata().map_err(|e| failure_of(&e))?;
|
let regular = |meta: &fs::Metadata| {
|
||||||
if !meta.is_file() {
|
if !meta.is_file() {
|
||||||
return Err(FileFailure::NotRegular);
|
return Err(FileFailure::NotRegular);
|
||||||
}
|
}
|
||||||
if meta.len() > MAX_PDF_BYTES as u64 {
|
if meta.len() > MAX_PDF_BYTES as u64 {
|
||||||
return Err(FileFailure::TooLarge);
|
return Err(FileFailure::TooLarge);
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
|
};
|
||||||
|
regular(&fs::metadata(path).map_err(|e| failure_of(&e))?)?;
|
||||||
|
let file = fs::File::open(path).map_err(|e| failure_of(&e))?;
|
||||||
|
regular(&file.metadata().map_err(|e| failure_of(&e))?)?;
|
||||||
// Bounded read: a file that grew after the size check is still refused.
|
// Bounded read: a file that grew after the size check is still refused.
|
||||||
let mut bytes = Vec::new();
|
let mut bytes = Vec::new();
|
||||||
file.take(MAX_PDF_BYTES as u64 + 1)
|
file.take(MAX_PDF_BYTES as u64 + 1)
|
||||||
|
|||||||
@@ -36,8 +36,12 @@ const WILDCARDS = new BlockList()
|
|||||||
WILDCARDS.addAddress('0.0.0.0', 'ipv4')
|
WILDCARDS.addAddress('0.0.0.0', 'ipv4')
|
||||||
WILDCARDS.addAddress('::', 'ipv6')
|
WILDCARDS.addAddress('::', 'ipv6')
|
||||||
|
|
||||||
|
// `dns.lookup` reports the family as 6, `server.address()` as 'IPv6'.
|
||||||
const isWildcard = ({ address, family }) =>
|
const isWildcard = ({ address, family }) =>
|
||||||
WILDCARDS.check(address.replace(/%.*$/, ''), family === 6 ? 'ipv6' : 'ipv4')
|
WILDCARDS.check(
|
||||||
|
address.replace(/%.*$/, ''),
|
||||||
|
family === 6 || family === 'IPv6' ? 'ipv6' : 'ipv4',
|
||||||
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The one address `host` names, resolved before any socket exists: an empty
|
* The one address `host` names, resolved before any socket exists: an empty
|
||||||
|
|||||||
Reference in new issue
Block a user