This is a good question, and you should look at the methodology of the specific survey you have in mind (which hopefully should be detailed in their report) to find out how they address that and justify the validity of the study.
For example, this interesting study of cannabis use prevalence in Canada from 1985 to 2015, examines nine national surveys and admits that:
Nevertheless, results of this study should be interpreted in light of
several limitations. Changes over time in respondents’ willingness to
admit drug use, in their definition of what constitutes drug use, and
in the perceived or real risk of legal consequences could neither be
controlled nor detected, but could affect trends
In the methodology of the 2021 US National Survey on Drug Use and Health, they address this issue by explaining:
Survey questions about topics such as substance use are considered to
be sensitive because respondents may think the questions are intrusive
(“none of your business”), pose risks for negative social or legal
consequences if their answers were to become known, or require them to
provide socially undesirable answers (Tourangeau & Yan, 2007).
NSDUH utilizes widely accepted methodological practices for increasing
the accuracy of self-reports, such as encouraging privacy through
self-administration of questions about sensitive topics—including
audio computer-assisted self-interviewing (ACASI) for in-person data
collection—and providing assurances that individual responses will
remain confidential. Comparisons using these methods within NSDUH data
(collected in person) have shown they reduce reporting bias (Gfroerer
et al., 2002).
In addition, in academia, they may use specific methods to address this kind of bias (e.g. social-desirability bias), including randomized response and list experiments. These methods allow plausible deniability for the respondent, hence limiting bias.
The principle of these methods is to make it impossible to know if a specific respondent uses drug or not; but if you aggregate all the responses, you can still estimate general prevalence after conducting some additional calculations. As for the details of each method, you should read the previous links. Both methods can have some issues or limitations, but may be better than asking directly a sensitive question. I mention specifically academia as using these methods, because I'm not sure that any national survey institute use these methods to estimate drug use prevalence (but happy to be corrected here).
Not all drug use surveys conducted in academia will use these "plausible deniability" methods, but here are some examples from academic papers using randomized response for estimating prevalence of cannabis/marijuana use or other drugs:
In addition, besides surveys, there are indirect methods for estimating prevalence, in particular when it's about drug used by a small proportion of the population or by a hard-to-reach population (e.g. heroin users). These methods include "multiplier-benchmark", "capture-recapture" (see this UN document from 2003 for an account of these two methods), or other methods. They are all subject to criticism, like any method.